removeRoute method

void removeRoute(
  1. BuildContext context, [
  2. Object? result
])

Remove the nearest page in context, if it exists. Do nothing if it doesn't exist.

If the route corresponds to a StandardPageInterface, it performs necessary cleanup and updates the page stack accordingly. If the route does not correspond to a StandardPageInterface, it directly removes the route from the navigator.

Implementation

void removeRoute(BuildContext context, [Object? result]) {
  assert(routerDelegate is StandardRouterDelegate);
  final tDelegate = routerDelegate as StandardRouterDelegate;

  final tRoute = ModalRoute.of(context);

  if (tRoute == null) {
    return;
  }

  tDelegate.removeRoute(tRoute, result);
}