Flutter Navigator 2.0

Nov 8 2022 Dart 2.17.3, Flutter 3.0.2, Android Studio 2020.3

Part 3: Use the Navigation

16. Go to the Previous Page

Episode complete

Play next episode

Next
Save for later
About this episode
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 15. Navigate to the Detail & ReadBook Pages Next episode: 17. Logout & Handle Back-Button

This video Go to the Previous Page was last updated on Nov 8 2022

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

You can unlock the rest of this video course, and our entire catalogue of books and videos, with a kodeco.com Professional subscription.

Episode - 16 Go to Previous Page

In application coming to the previous page is also important as much as going to the next page. So lets us create a function that will handle the poping of the pages. Create a private function with name

_handlePopPage()
bool _handelPopPages(Route<dynamic> route, result) {
    if (!route.didPop(result)) {
      return false;
    }
 }   
@override
Widget build(BuildContext context) {
  return Navigator(
    onPopPage: _handelPopPages,
    key: navigatorKey,
    pages: [],
   );
}   

  bool _handelPopPages(Route<dynamic> route, result) {
    if (!route.didPop(result)) {
      return false;
    }

    if (route.settings.name == BookPages.loginPath ||
        route.settings.name == BookPages.signupPath ||
        route.settings.name == BookPages.homePath) {
      appStateManager.logout();
    }

    if (route.settings.name == BookPages.detailsPath) {
      bookManager.bookTapped(-1);
    }
    if (route.settings.name == BookPages.cartPath) {
      appStateManager.onCartTapped(false);
    }
    if (route.settings.name == BookPages.settingsPath) {
      appStateManager.onSettingTapped(false);
    }
    if (route.settings.name == BookPages.checkoutPath) {
      appStateManager.onCheckoutTapped(false);
    }
    if (route.settings.name == BookPages.mybooksPath) {
      appStateManager.onMyBookTapped(false);
    }
    if (route.settings.name == BookPages.readBookPath) {
      appStateManager.onReadBookTapped(false);
    }

    return true;
  }