Web demo of Router usage.
Navigator 2.0 Pages API example and Router example.
The main point of these examples is to show how to extract basic navigation logic to separate class (e.g. ChangeNotifier). I'm using 2 approaches:
- Pages API
- Router widget
Both of them use separate PageManager
(or RoutePageManager
) to handle navigation stack.
Navigator's Pages API is a convenient way to declaratively set navigation stack in your Flutter app. Take a look at the main.dart
entry point and please notice custom PageManager
class that is handling list of pages provided to Navigator
.
For more complex and robust needs you may use the Router widget. Simple implementation can be found in main_router.dart
entry point. Take a look at the custom TheAppPath
class storing typed path information and RoutePageManager
handling list of pages provided to the Navigator
.
Because the RoutePageManager
is notifying the Router
about its changes and the currentPath
is used as currentConfiguration
the address bar in the browser is reflecting the stack changes:
@override
TheAppPath get currentConfiguration => pageManager.currentPath;
Run on Flutter dev (1.23)
Presentation at Flutter Cracow (Sept. 17th, 2020)
Presentation at DevFest Poland 2020
Presentation at Geekle Cross-Platform Mobile Development Summit 2020
Special thanks to Simon Lightfoot and Andrew Coutts.
See more also in the Stocks app example using Router.