I have an app where the home screen has two tabs; for handle the TabBar
navigation i use a StatefulShellRoute
where i pass the tabs to HomeScreen
screen with the navigatorContainerBuilder
param. In the HomeScreen i have a Drawer
that has other app routes like settings or account. to navigate to AccountScreen
i make a push and i can back to the HomeScreen with AppBar BackButton, but if i am in the web, and try to enter directly to AccountScreen
by url, I can't back to home because there is not more routes in the Stack. My workaround was to set manually a leading in AppBar and navigate to the HomeScreen with context.go()
, but this means that i have to do the same thing in every screen that is accessible trough the drawer, and also i can't make a pop with the browser back button. this is an example of the code:
GoRouter(
navigatorKey: navigatorKey,
initialLocation: '/splash',
routes: [
///------------ HOME SCREEN (2 TABS) ------------///
StatefulShellRoute(
builder: (context, state, navigationShell) {
return navigationShell;
},
navigatorContainerBuilder: (context, navigationShell, children) {
return HomeShell(navigationShell: navigationShell, children: children);
},
branches: [
///------------ TAB 1 ------------///
StatefulShellBranch(
routes: [
GoRoute(
path: '/tab1',
builder: (context, state) => const Tab1(),
)
]
),
///------------ TAB 2 ------------///
StatefulShellBranch(
routes: [
GoRoute(
path: '/tab2',
builder: (context, state) => const Tab2(),
)
]
)
],
),
///------------ ACCOUNT SCREEN ------------///
GoRoute(
path: '/account',
name: AccountScreen.name,
builder: (context, state) => const AccountScreen(),
),
]
);
I can't create a parent GoRoute because StatefulShellRoute and GoRoute are different type, so i don't know if there will be some way to do what i want. I would appreciate any advice or opinion.