finalizeRoute method Null safety

void finalizeRoute(
  1. Route route
)

Complete the lifecycle for a route that has been popped off the navigator.

When the navigator pops a route, the navigator retains a reference to the route in order to call Route.dispose if the navigator itself is removed from the tree. When the route is finished with any exit animation, the route should call this function to complete its lifecycle (e.g., to receive a call to Route.dispose).

The given route must have already received a call to Route.didPop. This function may be called directly from Route.didPop if Route.didPop will return true.

Implementation

void finalizeRoute(Route<dynamic> route) {
  // FinalizeRoute may have been called while we were already locked as a
  // responds to route.didPop(). Make sure to leave in the state we were in
  // before the call.
  bool? wasDebugLocked;
  assert(() { wasDebugLocked = _debugLocked; _debugLocked = true; return true; }());
  assert(_history.where(_RouteEntry.isRoutePredicate(route)).length == 1);
  final _RouteEntry entry =  _history.firstWhere(_RouteEntry.isRoutePredicate(route));
  if (entry.doingPop) {
    // We were called synchronously from Route.didPop(), but didn't process
    // the pop yet. Let's do that now before finalizing.
    entry.currentState = _RouteLifecycle.pop;
    _flushHistoryUpdates(rearrangeOverlay: false);
  }
  assert(entry.currentState != _RouteLifecycle.pop);
  entry.finalize();
  _flushHistoryUpdates(rearrangeOverlay: false);
  assert(() { _debugLocked = wasDebugLocked!; return true; }());
}