Previous episode: 20. Create a Navigation State Object
Next episode: 22. Support Web Url
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 navigation state is ready, let us parse the information that we get from our navigation. We are going to use route information parser for this. In the router directory, create a new file called as book router parser dot dart. And in this file create a book router parser class which extends route information parser with our Applink type. You can see our book router parser is throwing an error because we are not using the concrete functions present in our route information parser. Let us fix that error by overriding the method. So we need a parser route information to parse the route and we are going to need one more function, called as restore route information. We will override that as well. The parse route information contains the route information that we pass as a parameter into our function. This contains all the information of our route. We use this route information to create an Applink from the from location method that we have created in our Applink class. This will convert the URL string into Applink object which can be used in our application. As you can see, when we return the link, we get an error and the error states, "a value of type Applink can't be returned from the method parse route information because it has a return type of future Applink." So we will just write an async keyword over here and now the error is gone. The second function is called as the restore route information. This function takes an Applink as an object and converts it into the straight URL. We pass the Applink as a parameter in this function. First, let us change our configuration to Applink that we can use inside our function. And if you're going to return the route information and pass location as the parameter. Route information parser is created. Now that we have created the route information parser, it is now time to connect the parser with our router delegate so that whatever information the route parser gets can be passed to the router delegate. Open our main dot dart file and scroll to the top where you can see initialize the router parser and let us create an instance of our router parser. Don't forget to input the book router parser. Now scroll down to material app section and replace material app with material app dot router. Now pass this router property directly into our material app dot router. Remove the home parameter. You can see our material app router is throwing an error. It says that route information parser is missing. Let us add our book route parser that we created on top as the route information parser. And the error is gone. We are done with these TODOs, so I'm going to remove them. So how this works, the user enters the URL in the browser address bar, the route information parser parses the route into our navigation state, which is an instance of Applink. Based on the navigation state, router delegate updates the app state so that the new changes can be visible.
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.