Declarative routing with Navigator 2.0
Now that we have learned how to build our Hacker News application using Flutter’s legacy navigation APIs, we can refactor our Hacker News Application to use Flutter’s declarative Navigator 2.0 APIs. Specifically, we will look at how to use a newer library provided and maintained by the Flutter team called go_router
. Navigator 2.0 was introduced to provide a more powerful, declarative API that would empower developers who suffered from some of the shortcomings of Navigator 1.0, specifically the following:
- The inability to have more fine-grained control over the navigation stack.
- The inability to properly handle web URLs and deep linking.
- The inability to have state changes easily triggers navigation.
The Navigator 2.0 spec, while more powerful is a more low-level API that is missing many of Navigator 1.0’s capabilities, such as pushReplacement
or pushNamed
. Fortunately, Google actively maintains a library...