popRoute method
Handles back button/pop requests in the application
This method follows this sequence:
- First tries to handle any popup routes (dialogs, bottom sheets)
- Then attempts to pop based on the specified mode
- 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();
}
}