didPop method

  1. @override
void didPop(
  1. Route route,
  2. Route? previousRoute
)
override

The Navigator popped route.

The route immediately below that one, and thus the newly active route, is previousRoute.

Implementation

@override
void didPop(Route<dynamic> route, Route<dynamic>? previousRoute) {
  super.didPop(route, previousRoute);
  final currentRoute = _RouteData.ofRoute(route);
  final newRoute = _RouteData.ofRoute(previousRoute);

  if (currentRoute.isBottomSheet || currentRoute.isDialog) {
    logV("CLOSE ${currentRoute.name}");
  } else if (currentRoute.isPageRoute) {
    logV("CLOSE TO ROUTE ${currentRoute.name}");
  }

  if (previousRoute != null) {
    RouterReportManager.reportCurrentRoute(previousRoute);
  }

  if (Go.routingQueue.isNotEmpty) {
    Go.routingQueue.removeLast();
  }

  // Here we use a 'inverse didPush set', meaning that we use
  // previous route instead of 'route' because this is
  // a 'inverse push'
  routing?.update((value) {
    // Only PageRoute is allowed to change current value
    if (previousRoute is PageRoute) {
      value.current = _extractRouteName(previousRoute) ?? '';
      value.previous = newRoute.name ?? '';
    } else if (value.previous.isNotEmpty) {
      value.current = value.previous;
    }

    if (Go.routingQueue.isNotEmpty) {
      value.args = Go.routingQueue.last.args;
      value.previous = Go.routingQueue.last.previous;
    }

    value.route = previousRoute;
    value.isBack = true;
    value.removed = '';
    value.isBottomSheet = newRoute.isBottomSheet;
    value.isDialog = newRoute.isDialog;
  });
}