navigateTo method
Implementation
Future<void> navigateTo(String? url, {String? transition}) async {
// page in navigation history?
Page? page;
if (url == "/" && _pages.isNotEmpty) {
page = _pages.first;
} else {
page = _pages.reversed.firstWhereOrNull((page) => (page.name == url));
}
// navigate back to the page if found in the navigation history
if (page != null) {
bool notify = false;
// remove pages until target page encountered
while (_pages.isNotEmpty && _pages.last != page) {
bool canPop = await _canPop(_pages.last);
if (!canPop) break;
// remove the last page from the list
notify = true;
_pages.removeLast();
}
// notify listeners
if (notify) notifyListeners();
}
// open a new page
else {
_open(url, transition: transition);
}
}