animated-bottom-navigation-bar-flutter icon indicating copy to clipboard operation
animated-bottom-navigation-bar-flutter copied to clipboard

FAB position validation still throws exception with centered position

Open zeeshanahmad0201 opened this issue 1 year ago • 0 comments

Despite the previous fix in #23 , the position validation is still causing issues with centered FABs. The current validation uses exact position comparison which is too strict for real-world scenarios.

Current behavior:

  • Throws exception: "Wrong gap location in AnimatedBottomNavigationBar towards FloatingActionButtonLocation => consider use GapLocation.end instead of GapLocation.center"
  • Even when FAB and gap location are both set to center

Expected behavior:

  • Should work when FAB and gap locations are properly aligned
  • Should handle slight position variations due to floating-point precision

Proposed solution:

  • Implement threshold-based position validation
  • Use percentage-based tolerance (10% of width)
  • Replace integer comparisons with float comparisons

Example code showing the issue:

Scaffold(
  bottomNavigationBar: AnimatedBottomNavigationBar.builder(
      shadow: Shadow(
        color: context.colorScheme.secondary.withOpacity(0.25),
        blurRadius: 20.r,
      ),
      height: max(kBottomNavigationBarHeight, Dimens.navBarHeight),
      itemCount: BottomNavItem.values.length,
      tabBuilder: (int index, bool isActive) =>
          _buildNavItem(context, BottomNavItem.values[index], isActive),
      scaleFactor: 0.5,
      activeIndex: currentItem.index,
      onTap: (index) => context
          .read<BottomNavCubit>()
          .updateItem(BottomNavItem.values[index]),
      gapLocation: GapLocation.center,
      notchSmoothness: NotchSmoothness.softEdge,
    ),
  floatingActionButton: FloatingActionButton(...),
  floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
)

zeeshanahmad0201 avatar Nov 20 '24 12:11 zeeshanahmad0201