@@ -168,6 +168,18 @@ class GoRouteInformationParser extends RouteInformationParser<RouteMatchList> {
168
168
return redirectedFuture;
169
169
}
170
170
171
+ /// Ensures the replacement routes can resolve the originating route completer.
172
+ Completer <T ?>? _createInheritedCompleter <T >(
173
+ Completer <T ?> current,
174
+ RouteMatch lastRouteMatch,
175
+ ) {
176
+ if (lastRouteMatch is ImperativeRouteMatch ) {
177
+ return _InheritedCompleter <T ?>(current, lastRouteMatch.completer);
178
+ } else {
179
+ return current;
180
+ }
181
+ }
182
+
171
183
RouteMatchList _updateRouteMatchList (
172
184
RouteMatchList newMatchList, {
173
185
required RouteMatchList ? baseRouteMatchList,
@@ -185,6 +197,7 @@ class GoRouteInformationParser extends RouteInformationParser<RouteMatchList> {
185
197
);
186
198
case NavigatingType .pushReplacement:
187
199
final RouteMatch routeMatch = baseRouteMatchList! .last;
200
+ completer = _createInheritedCompleter (completer! , routeMatch);
188
201
baseRouteMatchList = baseRouteMatchList.remove (routeMatch);
189
202
if (baseRouteMatchList.isEmpty) {
190
203
return newMatchList;
@@ -198,6 +211,7 @@ class GoRouteInformationParser extends RouteInformationParser<RouteMatchList> {
198
211
);
199
212
case NavigatingType .replace:
200
213
final RouteMatch routeMatch = baseRouteMatchList! .last;
214
+ completer = _createInheritedCompleter (completer! , routeMatch);
201
215
baseRouteMatchList = baseRouteMatchList.remove (routeMatch);
202
216
if (baseRouteMatchList.isEmpty) {
203
217
return newMatchList;
@@ -224,3 +238,34 @@ class GoRouteInformationParser extends RouteInformationParser<RouteMatchList> {
224
238
List <int >.generate (32 , (_) => _random.nextInt (33 ) + 89 )));
225
239
}
226
240
}
241
+
242
+ /// Ensures the replacement routes can resolve the originating route completer.
243
+ /// Mainly used by [GoRouteInformationParser._createInheritedCompleter] .
244
+ class _InheritedCompleter <T extends Object ?> implements Completer <T > {
245
+ _InheritedCompleter (this ._current, this ._last);
246
+
247
+ final Completer <T > _current;
248
+ final Completer <Object ?> _last;
249
+
250
+ @override
251
+ void complete ([FutureOr <T >? value]) {
252
+ _current.complete (value);
253
+ if (! _last.isCompleted) {
254
+ _last.complete (value);
255
+ }
256
+ }
257
+
258
+ @override
259
+ void completeError (Object error, [StackTrace ? stackTrace]) {
260
+ _current.completeError (error, stackTrace);
261
+ if (! _last.isCompleted) {
262
+ _last.completeError (error, stackTrace);
263
+ }
264
+ }
265
+
266
+ @override
267
+ Future <T > get future => _current.future;
268
+
269
+ @override
270
+ bool get isCompleted => _current.isCompleted;
271
+ }
0 commit comments