Imperative Routing: Navigator 1.0
Explore how to use Flutter's Navigator 1.0 for imperative routing. Learn to navigate with anonymous and named routes, pass data between screens, and generate routes to manage app navigation efficiently.
We'll cover the following...
We got a brief overview of how Navigator 1.0 works in the previous lesson. We’ll learn how to use it in our app in this lesson. In the process, we’ll learn how to:
- Navigate with anonymous routes
- Navigate with named routes
- Pass arguments to routes
- Generate routes
Getting started
The app below has the screens mentioned in the previous lesson. Run it and follow through with the study as you implement imperative routing.
Anonymous routing
Once we have two screens implemented, we can accomplish anonymous routing in just two steps:
-
Step 1: Navigate to the second screen with
Navigator.push(), which adds aRouteto the navigation stack. We can addSettingsScreen()on top of the navigation stack. It will now be a visible screen to the user.In the app, replace line 49 of the
item_list_screen.dartfile with the code below:Navigator.push( context, MaterialPageRoute( builder: (context) => const SettingsScreen(), ), );
-
Step 2: Return to the first screen with ...