@@ -52,21 +52,7 @@ class GoRouterDelegate extends RouterDelegate<RouteMatchList>
52
52
53
53
@override
54
54
Future <bool > popRoute () async {
55
- NavigatorState ? state = navigatorKey.currentState;
56
- if (state == null ) {
57
- return false ;
58
- }
59
- if (! state.canPop ()) {
60
- state = null ;
61
- }
62
- RouteMatchBase walker = currentConfiguration.matches.last;
63
- while (walker is ShellRouteMatch ) {
64
- if (walker.navigatorKey.currentState? .canPop () ?? false ) {
65
- state = walker.navigatorKey.currentState;
66
- }
67
- walker = walker.matches.last;
68
- }
69
- assert (walker is RouteMatch );
55
+ final NavigatorState ? state = _findCurrentNavigator ();
70
56
if (state != null ) {
71
57
return state.maybePop ();
72
58
}
@@ -75,7 +61,8 @@ class GoRouterDelegate extends RouterDelegate<RouteMatchList>
75
61
if (lastRoute.onExit != null && navigatorKey.currentContext != null ) {
76
62
return ! (await lastRoute.onExit !(
77
63
navigatorKey.currentContext! ,
78
- walker.buildState (_configuration, currentConfiguration),
64
+ currentConfiguration.last
65
+ .buildState (_configuration, currentConfiguration),
79
66
));
80
67
}
81
68
return false ;
@@ -98,21 +85,33 @@ class GoRouterDelegate extends RouterDelegate<RouteMatchList>
98
85
99
86
/// Pops the top-most route.
100
87
void pop <T extends Object ?>([T ? result]) {
88
+ final NavigatorState ? state = _findCurrentNavigator ();
89
+ if (state == null ) {
90
+ throw GoError ('There is nothing to pop' );
91
+ }
92
+ state.pop (result);
93
+ }
94
+
95
+ NavigatorState ? _findCurrentNavigator () {
101
96
NavigatorState ? state;
102
97
if (navigatorKey.currentState? .canPop () ?? false ) {
103
98
state = navigatorKey.currentState;
104
99
}
105
100
RouteMatchBase walker = currentConfiguration.matches.last;
106
101
while (walker is ShellRouteMatch ) {
107
- if (walker.navigatorKey.currentState? .canPop () ?? false ) {
102
+ final NavigatorState potentialCandidate =
103
+ walker.navigatorKey.currentState! ;
104
+ if (! ModalRoute .of (potentialCandidate.context)! .isCurrent) {
105
+ // There is a pageless route on top of the shell route. it needs to be
106
+ // popped first.
107
+ break ;
108
+ }
109
+ if (potentialCandidate.canPop ()) {
108
110
state = walker.navigatorKey.currentState;
109
111
}
110
112
walker = walker.matches.last;
111
113
}
112
- if (state == null ) {
113
- throw GoError ('There is nothing to pop' );
114
- }
115
- state.pop (result);
114
+ return state;
116
115
}
117
116
118
117
void _debugAssertMatchListNotEmpty () {
0 commit comments