Implementing Navigator 2.0 in our app
Let’s start. As we are using Material Design and MaterialApp
, for simplicity, we will not be implementing our own Page
object, we will instead use MaterialPage
provided by Flutter’s material library. If you wish, you can implement Page
yourself by creating a new class that extends Page
and implementing the required functionality. So, we will start by implementing RouterDelegate
. RouterDelegate
requires a generic type that defines our route. Here, we will be using a Uniform Resource Identifier (URI) as it is powerful as well as simple. With a URI, we can provide advanced paths, as well as manipulate them easily. This is even more suitable for the web, as in the browser, we are always dealing with URIs. Inside lib/
, create a folder named routes
, and inside that folder, create a file called router_delegate.dart
. First, we will create our class by extending RouterDelegate
, setting URI as the generic type, like so:
class AppRouterDelegate...