Previous episode: 08. Create the Router Delegate
Next episode: 10. Create Material Pages
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 that our book Router Delegate is ready, let us use our delegate. Navigate to main.dart and find a tool where we have written Initialize the Router Delegate. Let us create a new private variable named Book Router Delegate. After creating the variable, we have to initialize the variable in the image state of the main dot file. Here you can see in the image state, we have written a To Do which says, Declare Router Delegate. Let us initialize it over there. The Book Router Delegate is equal to the Book Router Delegate. Our Book Router Delegate requires a book manager and an app state manager. We already have created an app state manager. Let us create a book manager, which we can pass inside our Book Router Delegate on top. Locate the initialized book manager and create book manager, just like we have an app state manager. Pass the newly created book manager inside our router delegate. This is how we initialized our app router before we use it. scroll down to our build method where we are returning the multi provider. In the Material App Home parameter where we're currently passing Splash Screen Pass Router Delegate as follow, so that we can set the router delegate to show the pages. Let us pass the Book Router Delegate over here. You can see the Book Router Delegate is throwing an error. That is because we are using a const material app. Let us remove the const variable from here. And now the error is gone. We do not need to import any screens, so scroll to the top and remove the splash screen import. Now let's run the application from this start and see what we are getting. As you can see, our application is throwing an error. It even might display a red screen of death error on the simulator. The error says navigator on a generate route was null, but the route named slash was referenced. Do not worry. This error was expected as navigator pages cannot be empty. The app threw an exception because it cannot generate a route. Let us fix this issue by adding pages to the navigator pages in our next segment.
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.