1

I am trying to create the following navigation:

|_ShellRoute
  |_GoRoute /a (needs bottomNav)
    |_GoRoute /a/nested/:id (does not need bottomNav)
  |_GoRoute /b (needs bottomNav)
  |_GoRoute /c (needs bottomNav)

However when I navigate to /a/nested/1 the bottom navigation still shows.

My route code (I am using type safe routes, but I think this stills applies to "normal" go_router):

final rootNavigatorKey = GlobalKey<NavigatorState>();

final router = GoRouter(
  routes: $appRoutes,
  initialLocation: '/a',
  navigatorKey: rootNavigatorKey,
);

final shellNavigatorKey = GlobalKey<NavigatorState>();

@TypedShellRoute<BottomShellRoute>(routes: [
  TypedGoRoute<ARoute>(path: '/a', routes: [
    TypedGoRoute<ANestedRoute>(path: 'nested/:id'),
  ]),
  TypedGoRoute<BRoute>(path: '/b'),
  TypedGoRoute<CRoute>(path: '/c'),
])
class BottomShellRoute extends ShellRouteData {
  const BottomShellRoute();

  static final GlobalKey<NavigatorState> $navigatorKey = shellNavigatorKey;

  @override
  Widget builder(BuildContext context, GoRouterState state, Widget navigator) => BottomShellScreen(
        location: state.location,
        child: navigator,
      );
}

Any idea how to make this route not show the bottom navigation?

Exprove
  • 1,301
  • 2
  • 18
  • 32

1 Answers1

0

One way to approach this would be to "hide" the bottom nav bar on certain routes. Meaning that the bottom nav bar is going to always be in the widget tree, just hidden from view.

This logic would live within the BottomShellScreen widget's build method.

Widget build(BuildContext context) {
   if (location == '/a/nested/:id'){
      return const SizedBox.shrink();
   }

   return ...;
}
mrgnhnt96
  • 3,562
  • 1
  • 17
  • 36
  • My workaround was similar. I made a function that checks if we are on the first navigation level (I want to hide the bottom navigation for all screens except for the first level). However this seems a workaround, but maybe it's the correct answer. If there is no better approach to achieve this, I will mark this as an asnwer. – Exprove May 08 '23 at 19:53