removeRouteBelow method
- Route anchorRoute
Immediately remove a route from the navigator, and Route.dispose it. The
route to be removed is the one below the given anchorRoute
.
The removed route is removed without being completed, so this method does not take a return value argument. No animations are run as a result of this method call.
The routes below and above the removed route are notified (see Route.didChangeNext and Route.didChangePrevious). If the Navigator has any Navigator.observers, they will be notified as well (see NavigatorObserver.didRemove). The removed route is disposed without being notified. The future that had been returned from pushing that routes will not complete.
The given anchorRoute
must be in the history and must have a route below
it; this method will throw an exception if it is not or does not.
Ongoing gestures within the current route are canceled.
Implementation
void removeRouteBelow(Route<dynamic> anchorRoute) {
assert(!_debugLocked);
assert(() {
_debugLocked = true;
return true;
}());
assert(anchorRoute._navigator == this);
final int anchorIndex = _history.indexWhere(_RouteEntry.isRoutePredicate(anchorRoute));
assert(anchorIndex >= 0, 'This Navigator does not contain the specified anchorRoute.');
assert(_history[anchorIndex].isPresent, 'The specified anchorRoute has already been removed from the Navigator.');
int index = anchorIndex - 1;
while (index >= 0) {
if (_history[index].isPresent) {
break;
}
index -= 1;
}
assert(index >= 0, 'There are no routes below the specified anchorRoute.');
_history[index].remove();
_flushHistoryUpdates(rearrangeOverlay: false);
assert(() {
_debugLocked = false;
return true;
}());
}