Your experience on this site will be improved by allowing cookies
An app has to display multiple screens depending upon the user’s needs. A user needs to back and forth from the multiple screens to the home screen. In, Flutter this is done with the help of Navigator.
Note: In Flutter, screens and pages are called routes.
In this article, we will explore the process of navigating through two named routes. To do so follow the below steps:
Let’s explore them in detail.
Here we will create two routes, the first route will have a single button that on tap leads to the second route, and similarly, the second route will have a single button that brings the user back to the first route. To do so follow the below code:
|
To switch to a new route, use the Navigator.push() method. The push() method adds a Route to the stack of routes managed by the Navigator. In the build() method of the first Route widget, update the onPressed() callback to lead to the second route as below:
|
To implement a return to the original route, update the onPressed() callback in the second Route as below:
|
Complete Source Code:
|
Output:
0 comments