@@ -2806,8 +2806,10 @@ class _RouteEntry extends RouteTransitionRecord {
2806
2806
_RouteEntry (
2807
2807
this .route, {
2808
2808
required _RouteLifecycle initialState,
2809
+ required this .pageBased,
2809
2810
this .restorationInformation,
2810
2811
}) : assert (route != null ),
2812
+ assert (! pageBased || route.settings is Page ),
2811
2813
assert (initialState != null ),
2812
2814
assert (
2813
2815
initialState == _RouteLifecycle .staging ||
@@ -2821,6 +2823,7 @@ class _RouteEntry extends RouteTransitionRecord {
2821
2823
@override
2822
2824
final Route <dynamic > route;
2823
2825
final _RestorationInformation ? restorationInformation;
2826
+ final bool pageBased;
2824
2827
2825
2828
static Route <dynamic > notAnnounced = _NotAnnounced ();
2826
2829
@@ -2834,7 +2837,7 @@ class _RouteEntry extends RouteTransitionRecord {
2834
2837
String ? get restorationId {
2835
2838
// User-provided restoration ids of Pages are prefixed with 'p+'. Generated
2836
2839
// ids for pageless routes are prefixed with 'r+' to avoid clashes.
2837
- if (hasPage ) {
2840
+ if (pageBased ) {
2838
2841
final Page <Object ?> page = route.settings as Page <Object ?>;
2839
2842
return page.restorationId != null ? 'p+${page .restorationId }' : null ;
2840
2843
}
@@ -2844,13 +2847,11 @@ class _RouteEntry extends RouteTransitionRecord {
2844
2847
return null ;
2845
2848
}
2846
2849
2847
- bool get hasPage => route.settings is Page ;
2848
-
2849
2850
bool canUpdateFrom (Page <dynamic > page) {
2850
2851
if (! willBePresent) {
2851
2852
return false ;
2852
2853
}
2853
- if (! hasPage ) {
2854
+ if (! pageBased ) {
2854
2855
return false ;
2855
2856
}
2856
2857
final Page <dynamic > routePage = route.settings as Page <dynamic >;
@@ -2937,7 +2938,7 @@ class _RouteEntry extends RouteTransitionRecord {
2937
2938
if (route._popCompleter.isCompleted) {
2938
2939
// This is a page-based route popped through the Navigator.pop. The
2939
2940
// didPop should have been called. No further action is needed.
2940
- assert (hasPage );
2941
+ assert (pageBased );
2941
2942
assert (pendingResult == null );
2942
2943
return true ;
2943
2944
}
@@ -2989,7 +2990,7 @@ class _RouteEntry extends RouteTransitionRecord {
2989
2990
// Route is removed without being completed.
2990
2991
void remove ({ bool isReplaced = false }) {
2991
2992
assert (
2992
- ! hasPage || isWaitingForExitingDecision,
2993
+ ! pageBased || isWaitingForExitingDecision,
2993
2994
'A page-based route cannot be completed using imperative api, provide a '
2994
2995
'new list without the corresponding Page to Navigator.pages instead. ' ,
2995
2996
);
@@ -3004,7 +3005,7 @@ class _RouteEntry extends RouteTransitionRecord {
3004
3005
// Route completes with `result` and is removed.
3005
3006
void complete <T >(T result, { bool isReplaced = false }) {
3006
3007
assert (
3007
- ! hasPage || isWaitingForExitingDecision,
3008
+ ! pageBased || isWaitingForExitingDecision,
3008
3009
'A page-based route cannot be completed using imperative api, provide a '
3009
3010
'new list without the corresponding Page to Navigator.pages instead. ' ,
3010
3011
);
@@ -3325,6 +3326,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin, Res
3325
3326
for (final Page <dynamic > page in widget.pages) {
3326
3327
final _RouteEntry entry = _RouteEntry (
3327
3328
page.createRoute (context),
3329
+ pageBased: true ,
3328
3330
initialState: _RouteLifecycle .add,
3329
3331
);
3330
3332
assert (
@@ -3349,6 +3351,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin, Res
3349
3351
widget.initialRoute ?? Navigator .defaultRouteName,
3350
3352
).map ((Route <dynamic > route) => _RouteEntry (
3351
3353
route,
3354
+ pageBased: false ,
3352
3355
initialState: _RouteLifecycle .add,
3353
3356
restorationInformation: route.settings.name != null
3354
3357
? _RestorationInformation .named (
@@ -3652,7 +3655,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin, Res
3652
3655
assert (oldEntry != null && oldEntry.currentState != _RouteLifecycle .disposed);
3653
3656
// Records pageless route. The bottom most pageless routes will be
3654
3657
// stored in key = null.
3655
- if (! oldEntry.hasPage ) {
3658
+ if (! oldEntry.pageBased ) {
3656
3659
final List <_RouteEntry > pagelessRoutes = pageRouteToPagelessRoutes.putIfAbsent (
3657
3660
previousOldPageRouteEntry,
3658
3661
() => < _RouteEntry > [],
@@ -3681,7 +3684,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin, Res
3681
3684
while ((oldEntriesBottom <= oldEntriesTop) && (newPagesBottom <= newPagesTop)) {
3682
3685
final _RouteEntry oldEntry = _history[oldEntriesTop];
3683
3686
assert (oldEntry != null && oldEntry.currentState != _RouteLifecycle .disposed);
3684
- if (! oldEntry.hasPage ) {
3687
+ if (! oldEntry.pageBased ) {
3685
3688
// This route might need to be skipped if we can not find a page above.
3686
3689
pagelessRoutesToSkip += 1 ;
3687
3690
oldEntriesTop -= 1 ;
@@ -3715,14 +3718,11 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin, Res
3715
3718
);
3716
3719
// Pageless routes will be recorded when we update the middle of the old
3717
3720
// list.
3718
- if (! oldEntry.hasPage ) {
3721
+ if (! oldEntry.pageBased ) {
3719
3722
continue ;
3720
3723
}
3721
3724
3722
- assert (oldEntry.hasPage);
3723
-
3724
3725
final Page <dynamic > page = oldEntry.route.settings as Page <dynamic >;
3725
-
3726
3726
if (page.key == null ) {
3727
3727
continue ;
3728
3728
}
@@ -3749,6 +3749,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin, Res
3749
3749
// it into the history.
3750
3750
final _RouteEntry newEntry = _RouteEntry (
3751
3751
nextPage.createRoute (context),
3752
+ pageBased: true ,
3752
3753
initialState: _RouteLifecycle .staging,
3753
3754
);
3754
3755
needsExplicitDecision = true ;
@@ -3773,7 +3774,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin, Res
3773
3774
final _RouteEntry potentialEntryToRemove = _history[oldEntriesBottom];
3774
3775
oldEntriesBottom += 1 ;
3775
3776
3776
- if (! potentialEntryToRemove.hasPage ) {
3777
+ if (! potentialEntryToRemove.pageBased ) {
3777
3778
assert (previousOldPageRouteEntry != null );
3778
3779
final List <_RouteEntry > pagelessRoutes = pageRouteToPagelessRoutes
3779
3780
.putIfAbsent (
@@ -3813,7 +3814,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin, Res
3813
3814
assert (() {
3814
3815
if (oldEntriesBottom <= oldEntriesTop) {
3815
3816
return newPagesBottom <= newPagesTop &&
3816
- _history[oldEntriesBottom].hasPage &&
3817
+ _history[oldEntriesBottom].pageBased &&
3817
3818
_history[oldEntriesBottom].canUpdateFrom (widget.pages[newPagesBottom]);
3818
3819
} else {
3819
3820
return newPagesBottom > newPagesTop;
@@ -3824,7 +3825,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin, Res
3824
3825
while ((oldEntriesBottom <= oldEntriesTop) && (newPagesBottom <= newPagesTop)) {
3825
3826
final _RouteEntry oldEntry = _history[oldEntriesBottom];
3826
3827
assert (oldEntry != null && oldEntry.currentState != _RouteLifecycle .disposed);
3827
- if (! oldEntry.hasPage ) {
3828
+ if (! oldEntry.pageBased ) {
3828
3829
assert (previousOldPageRouteEntry != null );
3829
3830
final List <_RouteEntry > pagelessRoutes = pageRouteToPagelessRoutes
3830
3831
.putIfAbsent (
@@ -4459,30 +4460,10 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin, Res
4459
4460
/// state restoration.
4460
4461
@optionalTypeArgs
4461
4462
Future <T ?> push <T extends Object ?>(Route <T > route) {
4462
- assert (_debugCheckIsPagelessRoute (route));
4463
- _pushEntry (_RouteEntry (route, initialState: _RouteLifecycle .push));
4463
+ _pushEntry (_RouteEntry (route, pageBased: false , initialState: _RouteLifecycle .push));
4464
4464
return route.popped;
4465
4465
}
4466
4466
4467
- bool _debugCheckIsPagelessRoute (Route <dynamic > route) {
4468
- assert (() {
4469
- if (route.settings is Page ) {
4470
- FlutterError .reportError (
4471
- FlutterErrorDetails (
4472
- exception: FlutterError (
4473
- 'A page-based route should not be added using the imperative api. '
4474
- 'Provide a new list with the corresponding Page to Navigator.pages instead.' ,
4475
- ),
4476
- library: 'widget library' ,
4477
- stack: StackTrace .current,
4478
- ),
4479
- );
4480
- }
4481
- return true ;
4482
- }());
4483
- return true ;
4484
- }
4485
-
4486
4467
bool _debugIsStaticCallback (Function callback) {
4487
4468
bool result = false ;
4488
4469
assert (() {
@@ -4610,8 +4591,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin, Res
4610
4591
Future <T ?> pushReplacement <T extends Object ?, TO extends Object ?>(Route <T > newRoute, { TO ? result }) {
4611
4592
assert (newRoute != null );
4612
4593
assert (newRoute._navigator == null );
4613
- assert (_debugCheckIsPagelessRoute (newRoute));
4614
- _pushReplacementEntry (_RouteEntry (newRoute, initialState: _RouteLifecycle .pushReplace), result);
4594
+ _pushReplacementEntry (_RouteEntry (newRoute, pageBased: false , initialState: _RouteLifecycle .pushReplace), result);
4615
4595
return newRoute.popped;
4616
4596
}
4617
4597
@@ -4698,8 +4678,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin, Res
4698
4678
assert (newRoute != null );
4699
4679
assert (newRoute._navigator == null );
4700
4680
assert (newRoute.overlayEntries.isEmpty);
4701
- assert (_debugCheckIsPagelessRoute (newRoute));
4702
- _pushEntryAndRemoveUntil (_RouteEntry (newRoute, initialState: _RouteLifecycle .push), predicate);
4681
+ _pushEntryAndRemoveUntil (_RouteEntry (newRoute, pageBased: false , initialState: _RouteLifecycle .push), predicate);
4703
4682
return newRoute.popped;
4704
4683
}
4705
4684
@@ -4777,7 +4756,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin, Res
4777
4756
assert (oldRoute != null );
4778
4757
assert (oldRoute._navigator == this );
4779
4758
assert (newRoute != null );
4780
- _replaceEntry (_RouteEntry (newRoute, initialState: _RouteLifecycle .replace), oldRoute);
4759
+ _replaceEntry (_RouteEntry (newRoute, pageBased : false , initialState: _RouteLifecycle .replace), oldRoute);
4781
4760
}
4782
4761
4783
4762
/// Replaces a route on the navigator with a new route.
@@ -4850,7 +4829,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin, Res
4850
4829
assert (newRoute._navigator == null );
4851
4830
assert (anchorRoute != null );
4852
4831
assert (anchorRoute._navigator == this );
4853
- _replaceEntryBelow (_RouteEntry (newRoute, initialState: _RouteLifecycle .replace), anchorRoute);
4832
+ _replaceEntryBelow (_RouteEntry (newRoute, pageBased : false , initialState: _RouteLifecycle .replace), anchorRoute);
4854
4833
}
4855
4834
4856
4835
/// Replaces a route on the navigator with a new route. The route to be
@@ -5004,7 +4983,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin, Res
5004
4983
return true ;
5005
4984
}());
5006
4985
final _RouteEntry entry = _history.lastWhere (_RouteEntry .isPresentPredicate);
5007
- if (entry.hasPage ) {
4986
+ if (entry.pageBased ) {
5008
4987
if (widget.onPopPage !(entry.route, result) && entry.currentState == _RouteLifecycle .idle) {
5009
4988
// The entry may have been disposed if the pop finishes synchronously.
5010
4989
assert (entry.route._popCompleter.isCompleted);
@@ -5139,7 +5118,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin, Res
5139
5118
final _RouteEntry entry = _history[index];
5140
5119
// For page-based route with zero transition, the finalizeRoute can be
5141
5120
// called on any life cycle above pop.
5142
- if (entry.hasPage && entry.currentState.index < _RouteLifecycle .pop.index) {
5121
+ if (entry.pageBased && entry.currentState.index < _RouteLifecycle .pop.index) {
5143
5122
_observedRouteDeletions.add (_NavigatorPopObservation (route, _getRouteBefore (index - 1 , _RouteEntry .willBePresentPredicate)? .route));
5144
5123
} else {
5145
5124
assert (entry.currentState == _RouteLifecycle .popping);
@@ -5343,6 +5322,7 @@ abstract class _RestorationInformation {
5343
5322
assert (route != null );
5344
5323
return _RouteEntry (
5345
5324
route,
5325
+ pageBased: false ,
5346
5326
initialState: initialState,
5347
5327
restorationInformation: this ,
5348
5328
);
@@ -5461,9 +5441,9 @@ class _HistoryProperty extends RestorableProperty<Map<String?, List<Object>>?> {
5461
5441
}
5462
5442
5463
5443
assert (entry.isPresentForRestoration);
5464
- if (entry.hasPage ) {
5444
+ if (entry.pageBased ) {
5465
5445
needsSerialization = needsSerialization || newRoutesForCurrentPage.length != oldRoutesForCurrentPage.length;
5466
- _finalizePage (newRoutesForCurrentPage, currentPage, newMap, removedPages);
5446
+ _finalizeEntry (newRoutesForCurrentPage, currentPage, newMap, removedPages);
5467
5447
currentPage = entry;
5468
5448
restorationEnabled = entry.restorationId != null ;
5469
5449
entry.restorationEnabled = restorationEnabled;
@@ -5478,7 +5458,7 @@ class _HistoryProperty extends RestorableProperty<Map<String?, List<Object>>?> {
5478
5458
continue ;
5479
5459
}
5480
5460
5481
- assert (! entry.hasPage );
5461
+ assert (! entry.pageBased );
5482
5462
restorationEnabled = restorationEnabled && (entry.restorationInformation? .isRestorable ?? false );
5483
5463
entry.restorationEnabled = restorationEnabled;
5484
5464
if (restorationEnabled) {
@@ -5493,7 +5473,7 @@ class _HistoryProperty extends RestorableProperty<Map<String?, List<Object>>?> {
5493
5473
}
5494
5474
}
5495
5475
needsSerialization = needsSerialization || newRoutesForCurrentPage.length != oldRoutesForCurrentPage.length;
5496
- _finalizePage (newRoutesForCurrentPage, currentPage, newMap, removedPages);
5476
+ _finalizeEntry (newRoutesForCurrentPage, currentPage, newMap, removedPages);
5497
5477
5498
5478
needsSerialization = needsSerialization || removedPages.isNotEmpty;
5499
5479
@@ -5505,13 +5485,13 @@ class _HistoryProperty extends RestorableProperty<Map<String?, List<Object>>?> {
5505
5485
}
5506
5486
}
5507
5487
5508
- void _finalizePage (
5488
+ void _finalizeEntry (
5509
5489
List <Object > routes,
5510
5490
_RouteEntry ? page,
5511
5491
Map <String ?, List <Object >> pageToRoutes,
5512
5492
Set <String ?> pagesToRemove,
5513
5493
) {
5514
- assert (page == null || page.hasPage );
5494
+ assert (page == null || page.pageBased );
5515
5495
assert (pageToRoutes != null );
5516
5496
assert (! pageToRoutes.containsKey (page? .restorationId));
5517
5497
if (routes != null && routes.isNotEmpty) {
@@ -5549,7 +5529,7 @@ class _HistoryProperty extends RestorableProperty<Map<String?, List<Object>>?> {
5549
5529
5550
5530
List <_RouteEntry > restoreEntriesForPage (_RouteEntry ? page, NavigatorState navigator) {
5551
5531
assert (isRegistered);
5552
- assert (page == null || page.hasPage );
5532
+ assert (page == null || page.pageBased );
5553
5533
final List <_RouteEntry > result = < _RouteEntry > [];
5554
5534
if (_pageToPagelessRoutes == null || (page != null && page.restorationId == null )) {
5555
5535
return result;
0 commit comments