removeRoute method

void removeRoute(
  1. Route route

Immediately remove route from the navigator, and Route.dispose it.

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 route must be in the history; this method will throw an exception if it is not.

Ongoing gestures within the current route are canceled.


void removeRoute(Route<dynamic> route) {
  assert(() {
    _debugLocked = true;
    return true;
  assert(route._navigator == this);
  final bool wasCurrent = route.isCurrent;
  final _RouteEntry entry = _history.firstWhere(_RouteEntry.isRoutePredicate(route));
  _flushHistoryUpdates(rearrangeOverlay: false);
  assert(() {
    _debugLocked = false;
    return true;
  if (wasCurrent) {