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

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.

Now that our navigation is done let us handle what happens when we press the back button and which screen to show. In application coming to the previous page is also important as much as going to the next page. So let us create a function that will handle the popping of the pages. Create a private function with name handle pop pages which returns a bold value. (silence) This function has two parameters, route and result. Let us add those two parameters over here. The route will be a dynamic parameter with having the type as route and result will be a normal parameter. The route parameter is the current route and as all the route information, like route settings from which we can retrieve the name and other arguments. And the result parameter is a call back result that we get after we have popped the pages. Now we will call the Data pop function from the pop navigator router delegate mixing that we mixed in this class and pass the result into the condition. If the condition is false, that means that pages were not popped. We return or false value else return true and have to handle the pages on how and what we popped and triggered the appropriate state change. (silence) And if this condition is false, we want to return false. So we have to make sure that this is the reverse condition that we get. So we'll add a not logical review. As we want to return true. In the navigation widget that we have passed in the build function, pass this function to the parameter called us on pop page. So in our navigator build function on pop page we are going to pass this handle pop pages function. If the route did pop result is false then we want to return false. And if the result is true, then we want to follow the conditions that we are going to write. Our route has a setting parameters, and from that we can get the name of the route that we are in. We are going to create some conditions which will help us figure out what should happen when the user presses the back button. To check the condition we will use the route settings parameter and in that settings parameter we have name which will give us the name of the route that we have. We will match that with the book pages path that we have created. And if that matches then we will pass the back button function that we want. Let us just add conditions that we have over here. (silence) If the name of the route is login path or signup path or Home Path and the user presses the back button then we want our app to call the logout function so that our user will be logged out from our application. (silence) If the route name is detailed speech and the user presses the back button then we want our book tapped selected index to be minus one so that we can come out of our detailed speech. The route name is scar part then we want to call the Encarta function from our abstract manager and pass a false value. Same goes with the other pages as well. (silence) (silence) Now let us run our application and check if everything is working as intended. (silence) So everything is working as expected.