- In 0.14.0 the way StateNotifierProvider and state/notifier reading work changed.
Changes#
-
StateNotifierProvider gets an extra type parameter: the state type.
- Before:
StateNotifierProvider<MyStateNotifier>(...) - After:
StateNotifierProvider<MyStateNotifier, MyModel>(...)
- Before:
-
Reading the notifier
- Before:
watch(provider)returned the StateNotifier. - After: use provider.notifier:
watch(provider.notifier)to get the StateNotifier.
- Before:
-
Reading the state
- Before:
watch(provider.state)for the state. - After:
watch(provider)returns the state directly.
- Before:
CLI migration#
- Install:
dart pub global activate riverpod_cli - In the project (do not upgrade Riverpod first): run riverpod migrate.
-
The tool will suggest edits (e.g.
watch(provider.state)âwatch(provider)). Accept withyor reject withn.