canPop method Null safety

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.

See also:


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