canPop method

bool canPop()

Whether the navigator can be popped.

The initial route cannot be popped off the navigator, which implies that this function returns true only if popping the navigator would not remove the initial route.

If there is no Navigator in scope, returns false.

Does not consider anything that might externally prevent popping, such as PopEntry.

See also:

Implementation

bool canPop() {
  final Iterator<_RouteEntry> iterator = _history.where(_RouteEntry.isPresentPredicate).iterator;
  if (!iterator.moveNext()) {
    // We have no active routes, so we can't pop.
    return false;
  }
  if (iterator.current.route.willHandlePopInternally) {
    // The first route can handle pops itself, so we can pop.
    return true;
  }
  if (!iterator.moveNext()) {
    // There's only one route, so we can't pop.
    return false;
  }
  return true; // there's at least two routes, so we can pop
}