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
About this episode
Leave a rating/review
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

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

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

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;
  }