Flutter Navigator 2.0

Nov 8 2022 · Dart 2.17.3, Flutter 3.0.2, Android Studio 2020.3

Part 2: Deep Dive Into Navigator 2.0

07. Use the New App State

Episode complete

Play next episode

About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 06. Create a Book Manager Class Next episode: 08. Create the Router Delegate

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 let us use this AppStateManager that we have created in the previous video in our application with provider. Now open the main.dart file in our lab folder. This has the main method and is the start of our application. Look at the TODO command which says, "TODO: initialize app state manager," and initialize the AppStateManager with the final keyword as follows. After initialing the AppStateManager, make sure you import the AppStateManager class in our main.dart file. To import the AppStateManager class in our main.dart file, click on the AppStateManager and press "command." To open the menu pane, click on "import library 'package:books/router/app_state_manager.dart'". Make sure that the imported file is present on top of a year. This is showing a warning that we are not using this field anywhere in our class. So let us initialize our AppStateManager via provider. To initialize the AppStateManager, locate a tool called as "Add MultiProvider". We are going to wrap our material class with MultiProvider, so that we can pass multiple providers before the root of the app is built. And we create an instance of our provider. To wrap a widget, click on the widget and press "command.", and you will get another page which says, "Wrap with widget," on top. Write "MultiProvider" when you wrap the widget. MultiProvider takes a list of providers in an argument called "AsProvider". Now let us pass our AppStateManager into the provider. So "ChangeNotifierProvider" is used to create a provider for our AppStateManager. The "create" takes a "context", and it requires us to return a class. Over here we are going to return our AppStateManager that we have created on top.