maybePop<T extends Object?> method

Future<bool> maybePop<T extends Object?>([
  1. T? result
])

Attempts to pops this page stack. Returns true if a route was successfully popped, otherwise false.

An optional value can be passed to the previous route via the result parameter.

Implementation

Future<bool> maybePop<T extends Object?>([T? result]) async {
  // First try delegating the pop to the last child route.
  final lastRoute = _pageContainers.last;
  if (lastRoute is MultiChildPageContainer &&
      await lastRoute.maybePop(result)) {
    notifyListeners();
    return SynchronousFuture(true);
  }

  // Child wasn't interested, ask the navigator
  if (await _attachedNavigator?.maybePop(result) == true) {
    notifyListeners();
    return SynchronousFuture(true);
  }

  // Pop the stack as a last resort
  if (_pageContainers.length > 1) {
    _pageContainers.removeLast();
    notifyListeners();
    return SynchronousFuture(true);
  }

  // Couldn't find anything to pop
  return SynchronousFuture(false);
}