@@ -244,7 +244,7 @@ void main() {
244
244
expect (await router.routerDelegate.popRoute (), false );
245
245
});
246
246
247
- testWidgets ('It should provide the correct state to the onExit callback' ,
247
+ testWidgets ('It should provide the correct uri to the onExit callback' ,
248
248
(WidgetTester tester) async {
249
249
final UniqueKey home = UniqueKey ();
250
250
final UniqueKey page1 = UniqueKey ();
@@ -314,4 +314,161 @@ void main() {
314
314
expect (find.byKey (home), findsOneWidget);
315
315
expect (onExitState1.uri.toString (), '/1' );
316
316
});
317
+
318
+ testWidgets (
319
+ 'It should provide the correct path parameters to the onExit callback' ,
320
+ (WidgetTester tester) async {
321
+ final UniqueKey page0 = UniqueKey ();
322
+ final UniqueKey page1 = UniqueKey ();
323
+ final UniqueKey page2 = UniqueKey ();
324
+ final UniqueKey page3 = UniqueKey ();
325
+ late final GoRouterState onExitState1;
326
+ late final GoRouterState onExitState2;
327
+ late final GoRouterState onExitState3;
328
+ final List <GoRoute > routes = < GoRoute > [
329
+ GoRoute (
330
+ path: '/route-0/:id0' ,
331
+ builder: (BuildContext context, GoRouterState state) =>
332
+ DummyScreen (key: page0),
333
+ ),
334
+ GoRoute (
335
+ path: '/route-1/:id1' ,
336
+ builder: (BuildContext context, GoRouterState state) =>
337
+ DummyScreen (key: page1),
338
+ onExit: (BuildContext context, GoRouterState state) {
339
+ onExitState1 = state;
340
+ return true ;
341
+ },
342
+ ),
343
+ GoRoute (
344
+ path: '/route-2/:id2' ,
345
+ builder: (BuildContext context, GoRouterState state) =>
346
+ DummyScreen (key: page2),
347
+ onExit: (BuildContext context, GoRouterState state) {
348
+ onExitState2 = state;
349
+ return true ;
350
+ },
351
+ ),
352
+ GoRoute (
353
+ path: '/route-3/:id3' ,
354
+ builder: (BuildContext context, GoRouterState state) {
355
+ return DummyScreen (key: page3);
356
+ },
357
+ onExit: (BuildContext context, GoRouterState state) {
358
+ onExitState3 = state;
359
+ return true ;
360
+ },
361
+ ),
362
+ ];
363
+
364
+ final GoRouter router = await createRouter (
365
+ routes,
366
+ tester,
367
+ initialLocation: '/route-0/0?param0=0' ,
368
+ );
369
+ unawaited (router.push ('/route-1/1?param1=1' ));
370
+ unawaited (router.push ('/route-2/2?param2=2' ));
371
+ unawaited (router.push ('/route-3/3?param3=3' ));
372
+
373
+ await tester.pumpAndSettle ();
374
+ expect (find.byKey (page3), findsOne);
375
+
376
+ router.pop ();
377
+ await tester.pumpAndSettle ();
378
+ expect (find.byKey (page2), findsOne);
379
+ expect (onExitState3.uri.toString (), '/route-3/3?param3=3' );
380
+ expect (onExitState3.pathParameters, const < String , String > {'id3' : '3' });
381
+ expect (onExitState3.fullPath, '/route-3/:id3' );
382
+
383
+ router.pop ();
384
+ await tester.pumpAndSettle ();
385
+ expect (find.byKey (page1), findsOne);
386
+ expect (onExitState2.uri.toString (), '/route-2/2?param2=2' );
387
+ expect (onExitState2.pathParameters, const < String , String > {'id2' : '2' });
388
+ expect (onExitState2.fullPath, '/route-2/:id2' );
389
+
390
+ router.pop ();
391
+ await tester.pumpAndSettle ();
392
+ expect (find.byKey (page0), findsOne);
393
+ expect (onExitState1.uri.toString (), '/route-1/1?param1=1' );
394
+ expect (onExitState1.pathParameters, const < String , String > {'id1' : '1' });
395
+ expect (onExitState1.fullPath, '/route-1/:id1' );
396
+ },
397
+ );
398
+
399
+ testWidgets (
400
+ 'It should provide the correct path parameters to the onExit callback during a go' ,
401
+ (WidgetTester tester) async {
402
+ final UniqueKey page0 = UniqueKey ();
403
+ final UniqueKey page1 = UniqueKey ();
404
+ final UniqueKey page2 = UniqueKey ();
405
+ final UniqueKey page3 = UniqueKey ();
406
+ late final GoRouterState onExitState0;
407
+ late final GoRouterState onExitState1;
408
+ late final GoRouterState onExitState2;
409
+ final List <GoRoute > routes = < GoRoute > [
410
+ GoRoute (
411
+ path: '/route-0/:id0' ,
412
+ builder: (BuildContext context, GoRouterState state) =>
413
+ DummyScreen (key: page0),
414
+ onExit: (BuildContext context, GoRouterState state) {
415
+ onExitState0 = state;
416
+ return true ;
417
+ },
418
+ ),
419
+ GoRoute (
420
+ path: '/route-1/:id1' ,
421
+ builder: (BuildContext context, GoRouterState state) =>
422
+ DummyScreen (key: page1),
423
+ onExit: (BuildContext context, GoRouterState state) {
424
+ onExitState1 = state;
425
+ return true ;
426
+ },
427
+ ),
428
+ GoRoute (
429
+ path: '/route-2/:id2' ,
430
+ builder: (BuildContext context, GoRouterState state) =>
431
+ DummyScreen (key: page2),
432
+ onExit: (BuildContext context, GoRouterState state) {
433
+ onExitState2 = state;
434
+ return true ;
435
+ },
436
+ ),
437
+ GoRoute (
438
+ path: '/route-3/:id3' ,
439
+ builder: (BuildContext context, GoRouterState state) {
440
+ return DummyScreen (key: page3);
441
+ },
442
+ ),
443
+ ];
444
+
445
+ final GoRouter router = await createRouter (
446
+ routes,
447
+ tester,
448
+ initialLocation: '/route-0/0?param0=0' ,
449
+ );
450
+ expect (find.byKey (page0), findsOne);
451
+
452
+ router.go ('/route-1/1?param1=1' );
453
+ await tester.pumpAndSettle ();
454
+ expect (find.byKey (page1), findsOne);
455
+ expect (onExitState0.uri.toString (), '/route-0/0?param0=0' );
456
+ expect (onExitState0.pathParameters, const < String , String > {'id0' : '0' });
457
+ expect (onExitState0.fullPath, '/route-0/:id0' );
458
+
459
+ router.go ('/route-2/2?param2=2' );
460
+ await tester.pumpAndSettle ();
461
+ expect (find.byKey (page2), findsOne);
462
+ expect (onExitState1.uri.toString (), '/route-1/1?param1=1' );
463
+ expect (onExitState1.pathParameters, const < String , String > {'id1' : '1' });
464
+ expect (onExitState1.fullPath, '/route-1/:id1' );
465
+
466
+ router.go ('/route-3/3?param3=3' );
467
+ await tester.pumpAndSettle ();
468
+ expect (find.byKey (page3), findsOne);
469
+ expect (onExitState2.uri.toString (), '/route-2/2?param2=2' );
470
+ expect (onExitState2.pathParameters, const < String , String > {'id2' : '2' });
471
+ expect (onExitState2.fullPath, '/route-2/:id2' );
472
+ },
473
+ );
317
474
}
0 commit comments