onPopPage method Null safety
Callback to handle imperative pop or operating system pop event.
route
request to be be pop/removed.
result
provided with the request to pop the route
.
Implementation
@visibleForTesting
bool onPopPage(Route<Object?> route, [Object? result]) {
final bool popSucceeded = route.didPop(result);
// In the imperative pop, the route can decline to be pop so we
// need to only update the page if the route has agreed to be pop.
if (popSucceeded) {
// the navigator pop always remove the top most page but for safety
// i prefer to look for the page before popping it.
DBPage? foundPage;
for (final DBPage page in _pages) {
if (page.name == route.settings.name) {
foundPage = page;
break;
}
}
_pages.remove(foundPage);
notifyListeners();
// if someone is waiting for the result, we remove it and signal
// the completion.
final Completer<Object?>? tracker =
_popResultTracker.remove(foundPage?.name);
if (tracker?.isCompleted == false) {
tracker?.complete(result);
}
}
return popSucceeded;
}