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

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.

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

So now that we are done with the navigation of the pages, let us now write the logout function. Navigate to the setting screen and scroll down to the logout button where we have the logging out function written beforehand. You can also find a todo which says logout from the app and then use nav 2 to navigate. I will remove the previously created function and we will write the new function to log out from our application. We will be calling the logout function from the app state manager using provider. Now let us refresh the application and check if we are able to log out from our application. Our application has been refreshed. Now let us go to the setting screen and click on the logout button. And we can see nothing is happening. That is because in our logout function we are changing some of the values to false, but still is setting stage is true and on cart tapped is true, and on my book tab is true. We will also have to change them to false, so in a logout function, add those values as well. Now if I will refresh the application, let us see what result we get. Logging in, going to the settings page, and if I click the logout button I'm coming back to the initialized. Let us try one more thing. Logging in, selecting a book, going to the details page, then going to the settings page and logging out. And you can see we are back at the detail screen. This is because we haven't changed the index, the selected book index, two minus one. So let us do that as well. Coming back to the settings page, I will call the function and set the selected book index to minus one. I have passed minus one index in the booked tab. Now let us refresh the application. This part is working. And this part is working as well. So now we have successfully logged out from our application. So what we did over here, so first we made sure that all the conditions are set to false, and then we also made sure that the selected book is to minus one to prevent going to the detail screen. Now if we will check this application on Android, you will notice that when you hit system back button, the app does not go to the previous screen, it exits the entire app. Let us fix this error, navigate to main.dot, scroll down to our router widget and set the value of back button dispatcher as root back button dispatcher. Now let us refresh the application and see what results we get. Right now we have disabled the back button.