setNewRoutePath method Null safety
- Destination configuration
override
Called by the Router when the Router.routeInformationProvider reports that a new route has been pushed to the application by the operating system.
Consider using a SynchronousFuture if the result can be computed synchronously, so that the Router does not need to wait for the next microtask to schedule a build.
Implementation
@override
Future<void> setNewRoutePath(Destination configuration) async {
final DBPage? newPage = await pageBuilders.getPage(configuration);
// Since this is called mostly for deep linking or web navigation
// if the path is unknown and can't be handle we just ignore it
// or we could return the user to a 404 page.
if (newPage != null) {
// map the current list of page to it's destination representation.
final Iterable<Destination> currentHistory = _pages.map(
(DBPage page) => page.destination,
);
// If the new page has a history than we need to check that it's not
// the same as the current one.
final List<Destination>? newPageHistory = configuration.metadata.history;
final Iterable<Destination> newPageFullHistory = <Destination>[
if (newPageHistory != null) ...newPageHistory,
configuration, // add the new destination requested.
];
// If the stack are equals then there's no point on updating the pages
// Because we might loose state of each screen and in a tabbed navigation
// this might be called when switching tabs.
if (!areNavigationStackEquals(currentHistory, newPageFullHistory)) {
// If the new stack is null or empty than we just add the new page.
if (newPageHistory == null || newPageHistory.isEmpty) {
_pages.add(newPage);
} else {
final List<DBPage> newPages =
await _pageBuilders.createPages(newPageHistory);
_pages
..addAll(newPages)
..add(newPage);
}
final Completer<Object> popTracker = Completer<Object>();
_popResultTracker[configuration.path] = popTracker;
}
}
}