Riverpod and go_router
Learning objectives
- You can use Riverpod with go_router.
Using Riverpod
for state management with go_router
works also as one would expect. When creating the MaterialApp
with the named constructor router
, the created application is wrapped with ProviderScope
. Now, all widgets that extend ConsumerWidget
have access to the WidgetRef
and through that to the providers in the application.
The following example outlines an application that creates screens based on a path variable. The screens have the possibility to move to the next (and the previous) screen. Further, the application uses a provider to keep track of screen visits -- on each transition, the count is incremented by one.