popRoute method

  1. @override
Future<bool> popRoute({
  1. Object? result,
  2. PopMode? popMode,
})
override

Handles back button/pop requests in the application

This method follows this sequence:

  1. First tries to handle any popup routes (dialogs, bottom sheets)
  2. Then attempts to pop based on the specified mode
  3. If neither succeeds, delegates to the system's default behavior

Implementation

@override
Future<bool> popRoute({
  Object? result,
  PopMode? popMode,
}) async {
  // First handle any popup routes (dialogs, bottom sheets, etc.)
  final wasPopup = await handlePopupRoutes(result: result);

  // Return early if a popup was handled
  if (wasPopup) return true;

  // Use the provided popMode or fall back to the default backButtonPopMode
  final mode = popMode ?? backButtonPopMode;

  // Handle pop based on whether we can pop with the current mode
  if (_canPop(mode)) {
    // We can pop something, so do it and notify listeners
    await _pop(mode, result);
    notifyListeners();
    return true;
  } else {
    // We can't pop anything, let the system handle it (may exit the app)
    return await super.popRoute();
  }
}