removeRoute<T extends Object?> method

  1. @optionalTypeArgs
void removeRoute<T extends Object?>(
  1. Route<T> route, [
  2. T? result
])

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

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 with its future completed.

The given route must be in the history; this method will throw an exception if it is not.

If non-null, result will be used as the result of the route that is removed; the future that had been returned from pushing the removed route will complete with result. If provided, must match the type argument of the class of the popped route (T).

The T type argument is the type of the return value of the popped route.

The type of result, if provided, must match the type argument of the class of the removed route (T).

Ongoing gestures within the current route are canceled.

Implementation

@optionalTypeArgs
void removeRoute<T extends Object?>(Route<T> route, [T? result]) {
  assert(!_debugLocked);
  assert(() {
    _debugLocked = true;
    return true;
  }());
  assert(route._navigator == this);
  final bool wasCurrent = route.isCurrent;
  final _RouteEntry entry = _history.firstWhere(_RouteEntry.isRoutePredicate(route));
  entry.complete(result);
  _flushHistoryUpdates(rearrangeOverlay: false);
  assert(() {
    _debugLocked = false;
    return true;
  }());
  if (wasCurrent) {
    _afterNavigation(_lastRouteEntryWhereOrNull(_RouteEntry.isPresentPredicate)?.route);
  }
}