removePoppedPageIfNotUserInitiated method
Removes the popped page if the navigation was not user initiated and there is a page to be removed.
Implementation
bool removePoppedPageIfNotUserInitiated(String? removedPageName) {
// If this page was marked to ignore (from Replace), ignore it
if (removedPageName != null &&
_pagesToIgnoreRemoval.contains(removedPageName)) {
_pagesToIgnoreRemoval.remove(removedPageName);
return false;
}
if (_isPerformingUserInitiatedNavigation ||
_resolvedNavigationStack.length < 2) {
return false;
}
// Check if dismiss is allowed
final allowed = _canDismissCurrentPage();
if (!allowed) {
return false;
}
// Add the action to keep breadcrumb navigation.
// Do not notify listeners to prevent duplicated navigation.
const dismissAction = Dismiss();
final canNavigate = _canNavigateFromCurrentPage(dismissAction);
if (!canNavigate) return false;
_commitNavigationStack(
_resolveNavigationStack(dismissAction),
dismissAction,
);
_trackNavigationAnalytics(dismissAction);
// When the system removes a page (e.g. tapping outside a modal bottom
// sheet), we still need to notify listeners so UI and view models that
// depend on navigation state can react. Schedule it post-frame to avoid
// potential duplicated removals while `Navigator` is already processing.
SchedulerBinding.instance.addPostFrameCallback((_) {
notifyListeners();
});
return true;
}