My app has a MainPage with with a BottomNavigationBar
with 3 tabs (A B C). The desired behavior is:
- Tab A: the state of this page is evaluated only the first time, since I do some long tasks and I want them to be executed only the first time. Tab A has also some subroutes, in which the user can add/delete/update some values on the local database.
- Tab B/C: the state of these pages is evaluated every time, since the data shown by these screens depends on the values of the local database (that can be modified from A’s subroutes)
At the moment I have implemented this routing structure:
final appRoutes = GoRouter(
initialLocation: A.route,
routes: [
StatefulShellRoute.indexedStack(
builder: (context, state, navigationShell) {
return ScaffoldWithBottomNavigation(navigationShell: navigationShell);
},
branches: [
StatefulShellBranch(
navigatorKey: _shellNavigatorAKey,
routes: [
GoRoute(
path: A.route,
pageBuilder: (context, state) => NoTransitionPage(
child: A(),
),
routes: [
GoRoute(
path: AA.route,
builder: (context, state) => AA(),
),
]),
StatefulShellBranch(
navigatorKey: _shellNavigatorBKey,
routes: [
GoRoute(
path: B.route,
pageBuilder: (context, state) => NoTransitionPage(
child: B(),
)
] )], ),
...
The problem with this is that the state is always stored (kinda obviously since I am using StatefulShellRoute
).
How can I archive the desired behavior wrote before?