@@ -1431,7 +1431,7 @@ void main() {
1431
1431
settings: const RouteSettings (name: 'C' ),
1432
1432
builder: (BuildContext context) {
1433
1433
log.add ('building C' );
1434
- log.add ('found ${ModalRoute .of (context )!. settings .name }' );
1434
+ log.add ('found ${ModalRoute .settingsOf (context )!.name }' );
1435
1435
return TextButton (
1436
1436
child: const Text ('C' ),
1437
1437
onPressed: () {
@@ -1476,7 +1476,7 @@ void main() {
1476
1476
final List <String > log = < String > [];
1477
1477
Route <dynamic >? nextRoute = PageRouteBuilder <int >(
1478
1478
pageBuilder: (BuildContext context, Animation <double > animation, Animation <double > secondaryAnimation) {
1479
- log.add ('building page 1 - ${ModalRoute .of (context )!. canPop }' );
1479
+ log.add ('building page 1 - ${ModalRoute .canPopOf (context )}' );
1480
1480
return const Placeholder ();
1481
1481
},
1482
1482
);
@@ -1493,32 +1493,83 @@ void main() {
1493
1493
expect (log, expected);
1494
1494
key.currentState! .pushReplacement (PageRouteBuilder <int >(
1495
1495
pageBuilder: (BuildContext context, Animation <double > animation, Animation <double > secondaryAnimation) {
1496
- log.add ('building page 2 - ${ModalRoute .of (context )!. canPop }' );
1496
+ log.add ('building page 2 - ${ModalRoute .canPopOf (context )}' );
1497
1497
return const Placeholder ();
1498
1498
},
1499
1499
));
1500
1500
expect (log, expected);
1501
1501
await tester.pump ();
1502
1502
expected.add ('building page 2 - false' );
1503
- expected.add ('building page 1 - false' ); // page 1 is rebuilt again because isCurrent changed.
1504
1503
expect (log, expected);
1505
1504
await tester.pump (const Duration (milliseconds: 150 ));
1506
1505
expect (log, expected);
1507
1506
key.currentState! .pushReplacement (PageRouteBuilder <int >(
1508
1507
pageBuilder: (BuildContext context, Animation <double > animation, Animation <double > secondaryAnimation) {
1509
- log.add ('building page 3 - ${ModalRoute .of (context )!. canPop }' );
1508
+ log.add ('building page 3 - ${ModalRoute .canPopOf (context )}' );
1510
1509
return const Placeholder ();
1511
1510
},
1512
1511
));
1513
1512
expect (log, expected);
1514
1513
await tester.pump ();
1515
1514
expected.add ('building page 3 - false' );
1516
- expected.add ('building page 2 - false' ); // page 2 is rebuilt again because isCurrent changed.
1517
1515
expect (log, expected);
1518
1516
await tester.pump (const Duration (milliseconds: 200 ));
1519
1517
expect (log, expected);
1520
1518
});
1521
1519
1520
+ testWidgets ('ModelRoute can be partially depended-on' , (WidgetTester tester) async {
1521
+ final GlobalKey <NavigatorState > key = GlobalKey <NavigatorState >();
1522
+ final List <String > log = < String > [];
1523
+ Route <dynamic >? nextRoute = PageRouteBuilder <int >(
1524
+ settings: const RouteSettings (name: 'page 1' ),
1525
+ pageBuilder: (BuildContext context, Animation <double > animation, Animation <double > secondaryAnimation) {
1526
+ log.add ('building ${ModalRoute .settingsOf (context )!.name } - canPop: ${ModalRoute .canPopOf (context )!}' );
1527
+ return const Placeholder ();
1528
+ },
1529
+ );
1530
+ await tester.pumpWidget (MaterialApp (
1531
+ navigatorKey: key,
1532
+ onGenerateRoute: (RouteSettings settings) {
1533
+ assert (nextRoute != null );
1534
+ final Route <dynamic > result = nextRoute! ;
1535
+ nextRoute = null ;
1536
+ return result;
1537
+ },
1538
+ ));
1539
+ final List <String > expected = < String > ['building page 1 - canPop: false' ];
1540
+ expect (log, expected);
1541
+ key.currentState! .push (PageRouteBuilder <int >(
1542
+ settings: const RouteSettings (name: 'page 2' ),
1543
+ pageBuilder: (BuildContext context, Animation <double > animation, Animation <double > secondaryAnimation) {
1544
+ log.add ('building ${ModalRoute .settingsOf (context )!.name } - isCurrent: ${ModalRoute .isCurrentOf (context )!}' );
1545
+ return const Placeholder ();
1546
+ },
1547
+ ));
1548
+ expect (log, expected);
1549
+ await tester.pump ();
1550
+ expected.add ('building page 2 - isCurrent: true' );
1551
+ expect (log, expected);
1552
+ key.currentState! .push (PageRouteBuilder <int >(
1553
+ settings: const RouteSettings (name: 'page 3' ),
1554
+ pageBuilder: (BuildContext context, Animation <double > animation, Animation <double > secondaryAnimation) {
1555
+ log.add ('building ${ModalRoute .settingsOf (context )!.name } - canPop: ${ModalRoute .canPopOf (context )!}' );
1556
+ return const Placeholder ();
1557
+ },
1558
+ ));
1559
+ expect (log, expected);
1560
+ await tester.pump ();
1561
+ expected.add ('building page 3 - canPop: true' );
1562
+ expected.add ('building page 2 - isCurrent: false' );
1563
+ expect (log, expected);
1564
+ key.currentState! .pop ();
1565
+ await tester.pump ();
1566
+ expected.add ('building page 2 - isCurrent: true' );
1567
+ expect (log, expected);
1568
+ key.currentState! .pop ();
1569
+ await tester.pump ();
1570
+ expect (log, expected);
1571
+ });
1572
+
1522
1573
testWidgets ('route semantics' , (WidgetTester tester) async {
1523
1574
final SemanticsTester semantics = SemanticsTester (tester);
1524
1575
final Map <String , WidgetBuilder > routes = < String , WidgetBuilder > {
0 commit comments