didPop method

  1. @override
bool didPop(
  1. T? result
)
override

A request was made to pop this route. If the route can handle it internally (e.g. because it has its own stack of internal state) then return false, otherwise return true (by returning the value of calling super.didPop). Returning false will prevent the default behavior of NavigatorState.pop.

When this function returns true, the navigator removes this route from the history but does not yet call dispose. Instead, it is the route's responsibility to call NavigatorState.finalizeRoute, which will in turn call dispose on the route. This sequence lets the route perform an exit animation (or some other visual effect) after being popped but prior to being disposed.

This method should call didComplete to resolve the popped future (and this is all that the default implementation does); routes should not wait for their exit animation to complete before doing so.

See popped, didComplete, and currentResult for a discussion of the result argument.

Implementation

@override
bool didPop(T? result) {
  if (willHandlePopInternally) {
    // A LocalHistoryEntry sits on top of this route - an overlay
    // flight (a menu, a popover) opened above the page. The pop
    // belongs to IT, not to this route's flight.
    return super.didPop(result);
  }
  _predictiveBack = false;
  final MorphFlight? flight = _flight;
  if (flight != null && !flight.isFinished) {
    // Hand the content back to the shuttle in the same frame the page
    // goes away, then play the ordinary close. close() is a no-op if
    // the flight is already closing. The pop result rides the
    // flight's own closed future too, so both calling conventions
    // agree.
    flight.routeOwnsContent.value = false;
    flight.close(result: result);
  }
  return super.didPop(result);
}