@@ -166,4 +166,81 @@ void main() {
166
166
await tester.pumpAndSettle ();
167
167
expect (find.byKey (home), findsOneWidget);
168
168
});
169
+
170
+ testWidgets ('android back button respects the last route.' ,
171
+ (WidgetTester tester) async {
172
+ bool allow = false ;
173
+ final UniqueKey home = UniqueKey ();
174
+ final List <GoRoute > routes = < GoRoute > [
175
+ GoRoute (
176
+ path: '/' ,
177
+ builder: (BuildContext context, GoRouterState state) =>
178
+ DummyScreen (key: home),
179
+ onExit: (BuildContext context) {
180
+ return allow;
181
+ },
182
+ ),
183
+ ];
184
+
185
+ final GoRouter router = await createRouter (routes, tester);
186
+ expect (find.byKey (home), findsOneWidget);
187
+
188
+ // Not allow system pop.
189
+ expect (await router.routerDelegate.popRoute (), true );
190
+
191
+ allow = true ;
192
+ expect (await router.routerDelegate.popRoute (), false );
193
+ });
194
+
195
+ testWidgets ('android back button respects the last route. async' ,
196
+ (WidgetTester tester) async {
197
+ bool allow = false ;
198
+ final UniqueKey home = UniqueKey ();
199
+ final List <GoRoute > routes = < GoRoute > [
200
+ GoRoute (
201
+ path: '/' ,
202
+ builder: (BuildContext context, GoRouterState state) =>
203
+ DummyScreen (key: home),
204
+ onExit: (BuildContext context) async {
205
+ return allow;
206
+ },
207
+ ),
208
+ ];
209
+
210
+ final GoRouter router = await createRouter (routes, tester);
211
+ expect (find.byKey (home), findsOneWidget);
212
+
213
+ // Not allow system pop.
214
+ expect (await router.routerDelegate.popRoute (), true );
215
+
216
+ allow = true ;
217
+ expect (await router.routerDelegate.popRoute (), false );
218
+ });
219
+
220
+ testWidgets ('android back button respects the last route with shell route.' ,
221
+ (WidgetTester tester) async {
222
+ bool allow = false ;
223
+ final UniqueKey home = UniqueKey ();
224
+ final List <RouteBase > routes = < RouteBase > [
225
+ ShellRoute (builder: (_, __, Widget child) => child, routes: < RouteBase > [
226
+ GoRoute (
227
+ path: '/' ,
228
+ builder: (BuildContext context, GoRouterState state) =>
229
+ DummyScreen (key: home),
230
+ onExit: (BuildContext context) {
231
+ return allow;
232
+ },
233
+ ),
234
+ ])
235
+ ];
236
+
237
+ final GoRouter router = await createRouter (routes, tester);
238
+ expect (find.byKey (home), findsOneWidget);
239
+
240
+ // Not allow system pop.
241
+ expect (await router.routerDelegate.popRoute (), true );
242
+
243
+ allow = true ;
244
+ expect (await router.routerDelegate.popRoute (), false );
245
+ });
169
246
}
0 commit comments