@@ -20,7 +20,9 @@ part 'app_router.g.dart';
20
20
21
21
// private navigators
22
22
final _rootNavigatorKey = GlobalKey <NavigatorState >();
23
- final _shellNavigatorKey = GlobalKey <NavigatorState >();
23
+ final _jobsNavigatorKey = GlobalKey <NavigatorState >(debugLabel: 'jobs' );
24
+ final _entriesNavigatorKey = GlobalKey <NavigatorState >(debugLabel: 'entries' );
25
+ final _accountNavigatorKey = GlobalKey <NavigatorState >(debugLabel: 'account' );
24
26
25
27
enum AppRoute {
26
28
onboarding,
@@ -73,120 +75,126 @@ GoRouter goRouter(GoRouterRef ref) {
73
75
GoRoute (
74
76
path: '/onboarding' ,
75
77
name: AppRoute .onboarding.name,
76
- pageBuilder: (context, state) => NoTransitionPage (
77
- key: state.pageKey,
78
- child: const OnboardingScreen (),
78
+ pageBuilder: (context, state) => const NoTransitionPage (
79
+ child: OnboardingScreen (),
79
80
),
80
81
),
81
82
GoRoute (
82
83
path: '/signIn' ,
83
84
name: AppRoute .signIn.name,
84
- pageBuilder: (context, state) => NoTransitionPage (
85
- key: state.pageKey,
86
- child: const CustomSignInScreen (),
85
+ pageBuilder: (context, state) => const NoTransitionPage (
86
+ child: CustomSignInScreen (),
87
87
),
88
88
),
89
- ShellRoute (
90
- navigatorKey: _shellNavigatorKey,
91
- builder: (context, state, child) {
92
- return ScaffoldWithBottomNavBar (child: child);
89
+ // Stateful navigation based on:
90
+ // https://github.com/flutter/packages/blob/main/packages/go_router/example/lib/stateful_shell_route.dart
91
+ StatefulShellRoute .indexedStack (
92
+ builder: (context, state, navigationShell) {
93
+ return ScaffoldWithBottomNavBar (navigationShell: navigationShell);
93
94
},
94
- routes: [
95
- GoRoute (
96
- path: '/jobs' ,
97
- name: AppRoute .jobs.name,
98
- pageBuilder: (context, state) => NoTransitionPage (
99
- key: state.pageKey,
100
- child: const JobsScreen (),
101
- ),
95
+ branches: [
96
+ StatefulShellBranch (
97
+ navigatorKey: _jobsNavigatorKey,
102
98
routes: [
103
99
GoRoute (
104
- path: 'add' ,
105
- name: AppRoute .addJob.name,
106
- parentNavigatorKey: _rootNavigatorKey,
107
- pageBuilder: (context, state) {
108
- return MaterialPage (
109
- key: state.pageKey,
110
- fullscreenDialog: true ,
111
- child: const EditJobScreen (),
112
- );
113
- },
114
- ),
115
- GoRoute (
116
- path: ':id' ,
117
- name: AppRoute .job.name,
118
- pageBuilder: (context, state) {
119
- final id = state.pathParameters['id' ]! ;
120
- return MaterialPage (
121
- key: state.pageKey,
122
- child: JobEntriesScreen (jobId: id),
123
- );
124
- },
100
+ path: '/jobs' ,
101
+ name: AppRoute .jobs.name,
102
+ pageBuilder: (context, state) => const NoTransitionPage (
103
+ child: JobsScreen (),
104
+ ),
125
105
routes: [
126
106
GoRoute (
127
- path: 'entries/ add' ,
128
- name: AppRoute .addEntry .name,
107
+ path: 'add' ,
108
+ name: AppRoute .addJob .name,
129
109
parentNavigatorKey: _rootNavigatorKey,
130
110
pageBuilder: (context, state) {
131
- final jobId = state.pathParameters['id' ]! ;
132
- return MaterialPage (
133
- key: state.pageKey,
111
+ return const MaterialPage (
134
112
fullscreenDialog: true ,
135
- child: EntryScreen (
136
- jobId: jobId,
137
- ),
138
- );
139
- },
140
- ),
141
- GoRoute (
142
- path: 'entries/:eid' ,
143
- name: AppRoute .entry.name,
144
- pageBuilder: (context, state) {
145
- final jobId = state.pathParameters['id' ]! ;
146
- final entryId = state.pathParameters['eid' ]! ;
147
- final entry = state.extra as Entry ? ;
148
- return MaterialPage (
149
- key: state.pageKey,
150
- child: EntryScreen (
151
- jobId: jobId,
152
- entryId: entryId,
153
- entry: entry,
154
- ),
113
+ child: EditJobScreen (),
155
114
);
156
115
},
157
116
),
158
117
GoRoute (
159
- path: 'edit ' ,
160
- name: AppRoute .editJob .name,
118
+ path: ':id ' ,
119
+ name: AppRoute .job .name,
161
120
pageBuilder: (context, state) {
162
- final jobId = state.pathParameters['id' ];
163
- final job = state.extra as Job ? ;
121
+ final id = state.pathParameters['id' ]! ;
164
122
return MaterialPage (
165
- key: state.pageKey,
166
- fullscreenDialog: true ,
167
- child: EditJobScreen (jobId: jobId, job: job),
123
+ child: JobEntriesScreen (jobId: id),
168
124
);
169
125
},
126
+ routes: [
127
+ GoRoute (
128
+ path: 'entries/add' ,
129
+ name: AppRoute .addEntry.name,
130
+ parentNavigatorKey: _rootNavigatorKey,
131
+ pageBuilder: (context, state) {
132
+ final jobId = state.pathParameters['id' ]! ;
133
+ return MaterialPage (
134
+ fullscreenDialog: true ,
135
+ child: EntryScreen (
136
+ jobId: jobId,
137
+ ),
138
+ );
139
+ },
140
+ ),
141
+ GoRoute (
142
+ path: 'entries/:eid' ,
143
+ name: AppRoute .entry.name,
144
+ pageBuilder: (context, state) {
145
+ final jobId = state.pathParameters['id' ]! ;
146
+ final entryId = state.pathParameters['eid' ]! ;
147
+ final entry = state.extra as Entry ? ;
148
+ return MaterialPage (
149
+ child: EntryScreen (
150
+ jobId: jobId,
151
+ entryId: entryId,
152
+ entry: entry,
153
+ ),
154
+ );
155
+ },
156
+ ),
157
+ GoRoute (
158
+ path: 'edit' ,
159
+ name: AppRoute .editJob.name,
160
+ pageBuilder: (context, state) {
161
+ final jobId = state.pathParameters['id' ];
162
+ final job = state.extra as Job ? ;
163
+ return MaterialPage (
164
+ fullscreenDialog: true ,
165
+ child: EditJobScreen (jobId: jobId, job: job),
166
+ );
167
+ },
168
+ ),
169
+ ],
170
170
),
171
171
],
172
172
),
173
173
],
174
174
),
175
- GoRoute (
176
- path: '/entries' ,
177
- name: AppRoute .entries.name,
178
- pageBuilder: (context, state) => NoTransitionPage (
179
- key: state.pageKey,
180
- child: const EntriesScreen (),
181
- ),
175
+ StatefulShellBranch (
176
+ navigatorKey: _entriesNavigatorKey,
177
+ routes: [
178
+ GoRoute (
179
+ path: '/entries' ,
180
+ name: AppRoute .entries.name,
181
+ pageBuilder: (context, state) => const NoTransitionPage (
182
+ child: EntriesScreen (),
183
+ ),
184
+ ),
185
+ ],
182
186
),
183
- GoRoute (
184
- path: '/account' ,
185
- name: AppRoute .profile.name,
186
- pageBuilder: (context, state) => NoTransitionPage (
187
- key: state.pageKey,
188
- child: const CustomProfileScreen (),
189
- ),
187
+ StatefulShellBranch (
188
+ navigatorKey: _accountNavigatorKey,
189
+ routes: [
190
+ GoRoute (
191
+ path: '/account' ,
192
+ name: AppRoute .profile.name,
193
+ pageBuilder: (context, state) => const NoTransitionPage (
194
+ child: CustomProfileScreen (),
195
+ ),
196
+ ),
197
+ ],
190
198
),
191
199
],
192
200
),
0 commit comments