I’m trying to provide an instance of GoRouter with riverpod. However, this results in the "The riverpod_generator package does not support ChangeNotifier values" warning to be displayed:
My question is, what would be the correct way of achieving this?
The warning is here to warn you about how Riverpod will neither listen to the ChangeNotifier nor dispose of it when the state is destroyed (which is what would happen if you were to use ChangeNotifierProvider).
If you do not care about these points, you can safely ignore the lint.
I’d recommend disposing the notifier manually as followed:
2
Answers
See this excellent article by Andrea: https://codewithandrea.com/articles/flutter-navigate-without-context-gorouter-riverpod/
Basically, what you want is a non-generator with the GoRouter object itself:
The warning is here to warn you about how Riverpod will neither listen to the ChangeNotifier nor dispose of it when the state is destroyed (which is what would happen if you were to use
ChangeNotifierProvider
).If you do not care about these points, you can safely ignore the lint.
I’d recommend disposing the notifier manually as followed: