Skip to content

Commit

Permalink
fix(lib-interfaces): fix presist FloatingActionButton on post story p…
Browse files Browse the repository at this point in the history
…age ds-12
  • Loading branch information
KeidsID committed Jan 15, 2025
1 parent 3c66e9c commit 7e65e98
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lib/interfaces/modules/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,15 @@ class _RootShellRouteScreenNavDelegate {
final String label;
final Icon? activeIcon;
final String routePath;

/// Only be rendered when the current route matches the [routePath].
final Widget? floatingActionButton;
}

mixin _RootShellRouteScreenNavHelperMixin on Widget {
double get minWidthForNavigationRail => 800.0;

/// Match [GoRouter] current route starts with the [navs] route path.
int _getCurrentNavigationIndex(
BuildContext context,
List<_RootShellRouteScreenNavDelegate> navs,
Expand All @@ -138,6 +141,19 @@ mixin _RootShellRouteScreenNavHelperMixin on Widget {

return navs.indexWhere((e) => currentRoute.startsWith(e.routePath));
}

/// Instead of matching the route starts like [_getCurrentNavigationIndex]
/// does, this method match the exact route path.
///
/// If there is no matched route, it returns -1.
int _getActualRouteMatchIndex(
BuildContext context,
List<_RootShellRouteScreenNavDelegate> navs,
) {
final currentRoute = GoRouterState.of(context).uri.path;

return navs.indexWhere((e) => currentRoute == e.routePath);
}
}

class _RootShellRouteScreenBody extends StatelessWidget
Expand Down Expand Up @@ -239,6 +255,7 @@ class _RootShellRouteScreenBottomNavBar extends StatelessWidget
return BottomNavigationBarItem(
icon: e.icon,
label: e.label,
activeIcon: e.activeIcon,
);
}).toList(),
);
Expand All @@ -263,11 +280,13 @@ class _RootShellRouteScreenFAB extends StatelessWidget

@override
Widget build(BuildContext context) {
final currentNavIndex = _getCurrentNavigationIndex(
final currentNavIndex = _getActualRouteMatchIndex(
context,
navigationDelegates,
);

if (currentNavIndex == -1) return const SizedBox.shrink();

return navigationDelegates[currentNavIndex].floatingActionButton ??
const SizedBox.shrink();
}
Expand Down

0 comments on commit 7e65e98

Please sign in to comment.