Skip to content

FAB position validation still throws exception with centered position #87

Open
@zeeshanahmad0201

Description

@zeeshanahmad0201

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,
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions