replaceRouteBelow<T extends Object?> method
Replaces a route on the navigator with a new route. The route to be
replaced is the one below the given anchorRoute
.
The old route must not be current visible, as this method skips the animations and therefore the removal would be jarring if it was visible. To replace the top-most route, consider pushReplacement instead, which does animate the new route, and delays removing the old route until the new route has finished animating.
The removed route is removed without being completed, so this method does not take a return value argument.
The new route, the route below the new route (if any), and the route above the new route, are all notified (see Route.didReplace, Route.didChangeNext, and Route.didChangePrevious). If the Navigator has any Navigator.observers, they will be notified as well (see NavigatorObserver.didReplace). The removed route is disposed without being notified. The future that had been returned from pushing that routes will not complete.
The T
type argument is the type of the return value of the new route.
See also:
- replace, which is the same but identifies the route to be removed directly.
- restorableReplaceRouteBelow, which adds a replacement route that can be restored during state restoration.
Implementation
@optionalTypeArgs
void replaceRouteBelow<T extends Object?>({ required Route<dynamic> anchorRoute, required Route<T> newRoute }) {
assert(newRoute._navigator == null);
assert(anchorRoute._navigator == this);
_replaceEntryBelow(_RouteEntry(newRoute, pageBased: false, initialState: _RouteLifecycle.replace), anchorRoute);
}