I have a page called 'clubview' which is inside the StatefulShellRoute. When a user is in this page he can navigate to another page called 'createClub'.
I need a way to show BottomNavigationBar whenever I want, in this case I want it to show when a user is in the 'clubview' and not when they push 'createClub'. I can make it work if i use GoNamed but then I can not go back by doing pop(). So, is there a way to show BottomNavigationBar only in certain routes while using pushNamed?
my code looks partially like this:
note: I could even make 'createClub' a subroute of 'clubview' but even that I can not make it work. Tried searching on the web but there is very limited resources about StatefulShellRoute.indexStack
GoRouter(
navigatorKey: _rootNavigatorKey,
initialLocation: initialLocation,
refreshListenable: GoRouterRefreshStream(authBloc.stream),
redirect: (context, state) {
if (authBloc.state is AuthUnauthenticatedState) {
if (state.location == Routes.login.path ||
state.location == Routes.register.path ||
state.location.startsWith(Routes.passwordreset.path)) {
return null;
} else if (state.location == Routes.verifyemail.path ||
state.location == Routes.chooseName.path) {
return Routes.register.path;
} else {
return Routes.login.path;
}
} else if (authBloc.state is AuthChooseNameState &&
state.location != Routes.chooseName.path) {
return Routes.chooseName.path;
} else if (authBloc.state is AuthVerifyEmaildState &&
state.location != Routes.verifyemail.path) {
return Routes.verifyemail.path;
} else if (authBloc.state is AuthAuthenticatedState &&
(state.location == Routes.login.path ||
state.location == Routes.register.path ||
state.location == Routes.chooseName.path ||
state.location == Routes.verifyemail.path)) {
return Routes.clubview.path;
} else if (authBloc.state is ColdStartLogin &&
(state.location == Routes.login.path ||
state.location == Routes.register.path ||
state.location == Routes.chooseName.path ||
state.location == Routes.verifyemail.path)) {
return Routes.clubview.path;
} else {
//if (state.location == Routes.createClub.path ||
// state.location == Routes.mediaPicker.path) {
// BlocProvider.of<InstantFadecubit>(context).hideBottomBar();
//} else {
// BlocProvider.of<InstantFadecubit>(context).showBottomBar();
//}
return null;
}
},
routes: [
GoRoute(
//parentNavigatorKey: _rootNavigatorKey,
name: Routes.home.name,
path: Routes.home.path,
builder: (context, state) => const HomePage(),
),
GoRoute(
//parentNavigatorKey: _rootNavigatorKey,
name: Routes.login.name,
path: Routes.login.path,
builder: (context, state) => const LoginPage(),
),
GoRoute(
//parentNavigatorKey: _rootNavigatorKey,
name: Routes.register.name,
path: Routes.register.path,
builder: (context, state) => const RegisterPage(),
),
GoRoute(
//parentNavigatorKey: _rootNavigatorKey,
name: Routes.chooseName.name,
path: Routes.chooseName.path,
builder: (context, state) => const ChooseName(),
),
StatefulShellRoute.indexedStack(
//parentNavigatorKey: _rootNavigatorKey,
builder: (context, state, navigationShell) {
return DashboardScreen(key: state.pageKey, child: navigationShell);
},
branches: <StatefulShellBranch>[
StatefulShellBranch(
//navigatorKey: _shellNavigatorKey,
routes: <RouteBase>[
GoRoute(
name: Routes.clubview.name,
path: Routes.clubview.path,
builder: (context, state) => const ClubView()),
],
),
StatefulShellBranch(
//navigatorKey: _shellNavigatorKey,
routes: <RouteBase>[
GoRoute(
name: Routes.searchEngine.name,
path: Routes.searchEngine.path,
builder: (context, state) => const SearchEngine(),
),
],
),
StatefulShellBranch(
//navigatorKey: _shellNavigatorKey,
routes: <RouteBase>[
GoRoute(
name: Routes.mapa.name,
path: Routes.mapa.path,
builder: (context, state) => const Map1(),
),
],
),
StatefulShellBranch(
//navigatorKey: _shellNavigatorKey,
routes: <RouteBase>[
GoRoute(
name: Routes.profile.name,
path: Routes.profile.path,
builder: (context, state) => const Profile(),
),
],
),
],
),
GoRoute(
//parentNavigatorKey: _rootNavigatorKey,
name: Routes.verifyemail.name,
path: Routes.verifyemail.path,
builder: (context, state) => const VerifyEmail(),
),
GoRoute(
//parentNavigatorKey: _rootNavigatorKey,
path: '${Routes.passwordreset.path}/:email',
name: Routes.passwordreset.name,
builder: (context, state) => PasswordReset(
email: state.pathParameters['email']!,
),
),
GoRoute(
//parentNavigatorKey: _rootNavigatorKey,
path: Routes.passwordreset.path,
name: '${Routes.passwordreset.name}null',
builder: (context, state) => const PasswordReset()),
GoRoute(
//parentNavigatorKey: _rootNavigatorKey,
path: Routes.clubpage.path,
name: Routes.clubpage.name,
builder: (context, state) {
if (state.extra is ClubOverview) {
final club = state.extra as ClubOverview;
return ClubPage(club: club);
} else {
final club =
ClubOverview.fromMap(state.extra as Map<String, dynamic>);
return ClubPage(club: club);
}
},
),
GoRoute(
//parentNavigatorKey: _rootNavigatorKey,
name: Routes.createClub.name,
path: Routes.createClub.path,
pageBuilder: (context, state) {
return CustomTransitionPage(
key: state.pageKey,
transitionDuration: const Duration(milliseconds: 300),
reverseTransitionDuration: const Duration(milliseconds: 300),
child: const ClubForm(),
transitionsBuilder:
(context, animation, secondaryAnimation, child) {
return Transform.scale(
scale: Tween<double>(begin: 0, end: 1).evaluate(animation),
child: child,
);
},
);
},
),
GoRoute(
//parentNavigatorKey: _rootNavigatorKey,
name: Routes.createPost.name,
path: Routes.createPost.path,
builder: (context, state) {
final club = state.extra as ClubProfile;
return CreatePost(clubProfile: club);
},
),
GoRoute(
//parentNavigatorKey: _rootNavigatorKey,
name: Routes.mediaPicker.name,
path: Routes.mediaPicker.path,
builder: (context, state) {
final Map<String, dynamic> extraData =
state.extra as Map<String, dynamic>;
// Extract any necessary parameters from the state.extra if needed
final maxCount = extraData['maxCount'] as int;
final requestType = extraData['requestType'] as RequestType;
return ImageMediaPicker(
maxCount: maxCount, requestType: requestType);
},
),
],
);
show and hide BottomNavigationBar depending on the route using go_router StatefulShellRoute.indexStack while also using pushnamed to navigate routes