removeRoute static method

void removeRoute(
  1. BuildContext context,
  2. Route route

Immediately remove route from the navigator that most tightly encloses the given context, 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.

This method is used, for example, to instantly dismiss dropdown menus that are up when the screen's orientation changes.


static void removeRoute(BuildContext context, Route<dynamic> route) {
  return Navigator.of(context).removeRoute(route);