@@ -25,7 +25,7 @@ void main() {
25
25
path: '1' ,
26
26
builder: (BuildContext context, GoRouterState state) =>
27
27
DummyScreen (key: page1),
28
- onExit: (BuildContext context) {
28
+ onExit: (BuildContext context, GoRouterState state ) {
29
29
return allow;
30
30
},
31
31
)
@@ -61,7 +61,7 @@ void main() {
61
61
path: '/1' ,
62
62
builder: (BuildContext context, GoRouterState state) =>
63
63
DummyScreen (key: page1),
64
- onExit: (BuildContext context) {
64
+ onExit: (BuildContext context, GoRouterState state ) {
65
65
return allow;
66
66
},
67
67
)
@@ -95,7 +95,7 @@ void main() {
95
95
path: '1' ,
96
96
builder: (BuildContext context, GoRouterState state) =>
97
97
DummyScreen (key: page1),
98
- onExit: (BuildContext context) async {
98
+ onExit: (BuildContext context, GoRouterState state ) async {
99
99
return allow.future;
100
100
},
101
101
)
@@ -139,7 +139,7 @@ void main() {
139
139
path: '/1' ,
140
140
builder: (BuildContext context, GoRouterState state) =>
141
141
DummyScreen (key: page1),
142
- onExit: (BuildContext context) async {
142
+ onExit: (BuildContext context, GoRouterState state ) async {
143
143
return allow.future;
144
144
},
145
145
)
@@ -176,7 +176,7 @@ void main() {
176
176
path: '/' ,
177
177
builder: (BuildContext context, GoRouterState state) =>
178
178
DummyScreen (key: home),
179
- onExit: (BuildContext context) {
179
+ onExit: (BuildContext context, GoRouterState state ) {
180
180
return allow;
181
181
},
182
182
),
@@ -201,7 +201,7 @@ void main() {
201
201
path: '/' ,
202
202
builder: (BuildContext context, GoRouterState state) =>
203
203
DummyScreen (key: home),
204
- onExit: (BuildContext context) async {
204
+ onExit: (BuildContext context, GoRouterState state ) async {
205
205
return allow;
206
206
},
207
207
),
@@ -227,7 +227,7 @@ void main() {
227
227
path: '/' ,
228
228
builder: (BuildContext context, GoRouterState state) =>
229
229
DummyScreen (key: home),
230
- onExit: (BuildContext context) {
230
+ onExit: (BuildContext context, GoRouterState state ) {
231
231
return allow;
232
232
},
233
233
),
@@ -243,4 +243,75 @@ void main() {
243
243
allow = true ;
244
244
expect (await router.routerDelegate.popRoute (), false );
245
245
});
246
+
247
+ testWidgets ('It should provide the correct state to the onExit callback' ,
248
+ (WidgetTester tester) async {
249
+ final UniqueKey home = UniqueKey ();
250
+ final UniqueKey page1 = UniqueKey ();
251
+ final UniqueKey page2 = UniqueKey ();
252
+ final UniqueKey page3 = UniqueKey ();
253
+ late final GoRouterState onExitState1;
254
+ late final GoRouterState onExitState2;
255
+ late final GoRouterState onExitState3;
256
+ final List <GoRoute > routes = < GoRoute > [
257
+ GoRoute (
258
+ path: '/' ,
259
+ builder: (BuildContext context, GoRouterState state) =>
260
+ DummyScreen (key: home),
261
+ routes: < GoRoute > [
262
+ GoRoute (
263
+ path: '1' ,
264
+ builder: (BuildContext context, GoRouterState state) =>
265
+ DummyScreen (key: page1),
266
+ onExit: (BuildContext context, GoRouterState state) {
267
+ onExitState1 = state;
268
+ return true ;
269
+ },
270
+ routes: < GoRoute > [
271
+ GoRoute (
272
+ path: '2' ,
273
+ builder: (BuildContext context, GoRouterState state) =>
274
+ DummyScreen (key: page2),
275
+ onExit: (BuildContext context, GoRouterState state) {
276
+ onExitState2 = state;
277
+ return true ;
278
+ },
279
+ routes: < GoRoute > [
280
+ GoRoute (
281
+ path: '3' ,
282
+ builder: (BuildContext context, GoRouterState state) =>
283
+ DummyScreen (key: page3),
284
+ onExit: (BuildContext context, GoRouterState state) {
285
+ onExitState3 = state;
286
+ return true ;
287
+ },
288
+ )
289
+ ],
290
+ )
291
+ ],
292
+ )
293
+ ],
294
+ ),
295
+ ];
296
+
297
+ final GoRouter router =
298
+ await createRouter (routes, tester, initialLocation: '/1/2/3' );
299
+ expect (find.byKey (page3), findsOneWidget);
300
+
301
+ router.pop ();
302
+ await tester.pumpAndSettle ();
303
+ expect (find.byKey (page2), findsOneWidget);
304
+
305
+ expect (onExitState3.uri.toString (), '/1/2/3' );
306
+
307
+ router.pop ();
308
+ await tester.pumpAndSettle ();
309
+ expect (find.byKey (page1), findsOneWidget);
310
+ expect (onExitState2.uri.toString (), '/1/2' );
311
+
312
+ router.pop ();
313
+ await tester.pumpAndSettle ();
314
+ expect (find.byKey (home), findsOneWidget);
315
+ expect (onExitState1.uri.toString (), '/1' );
316
+ });
246
317
}
0 commit comments