Flutter Navigator 2.0

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

Part 3: Use the Navigation

17. Logout & Handle Back-Button

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: 16. Go to the Previous Page Next episode: 18. Learn Deep Links

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.

Transcript: 17. Logout & Handle Back-Button

Episode - 17 Logout & Handle Back-Button

Now that we are done with the navigation of the pages. Let us now write the logout function. in the settings page on the logout button pressed add the following code.


 Provider.of<BookManager>(context, listen: false)
     .bookTapped(-1);
 Provider.of<AppStateManager>(context, listen: false)
     .onMyBookTapped(false);
 Provider.of<AppStateManager>(context, listen: false)
     .onCartTapped(false);
 Provider.of<AppStateManager>(context, listen: false)
     .onSettingTapped(false);
 Provider.of<AppStateManager>(context, listen: false).logout();

What we do here. Login out from the app we have make sure everthing is back to normal when our app was loaded for the first time. First me change the index of the selectedBook to -1 to prevent from going to detailScreens. We change the bool values to false of the appStartManager of onMyBookTapped, onCartTapped, onSettingTable and finally we call the logout function from the appStateManager. Reload the application and check the logout function, this will take us back to SplashScreen.

BackButtonDispatcher. If you check this application on android you will notice that the app does not go to previous screen but it exits the entire app. To fix this open main.dart, and in Router widget set value of backButtonDispatcher as RootBackButtonDispatcher().

backButtonDispatcher: RootBackButtonDispatcher(),