void removeRoute(BuildContext context, Route route)

Immediately remove route and Route.dispose it.

The route's animation does not run and the future returned from pushing the route will not complete. Ongoing input gestures are cancelled. If the Navigator has any Navigator.observers, they will be notified with NavigatorObserver.didRemove.

The routes before and after the removed route, if any, are notified with Route.didChangeNext and Route.didChangePrevious.

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

Source

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