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.
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.
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.