Provider type summary#
- Provider â sync, unmodifiable. Return type
T. - FutureProvider â async, unmodifiable. Return type
Future<T>. - StreamProvider â stream, unmodifiable. Return type
Stream<T>. -
NotifierProvider â sync, modifiable. Notifier extends
Notifier<T>,build()returnsT. -
AsyncNotifierProvider â async, modifiable. Notifier extends
AsyncNotifier<T>,build()returnsFuture<T>. -
StreamNotifierProvider â stream, modifiable. Notifier extends
StreamNotifier<T>,build()returnsStream<T>.
Modifiers#
-
autoDispose â Cache is cleared when the provider has no listeners. Use with family to avoid memory leaks. Disable with
@Riverpod(keepAlive: true)in codegen. -
family â Pass parameters to the provider (e.g.
provider(id)). See riverpod-family.
Notifier rules#
-
Do not put logic in the Notifier constructor;
refandstateare not ready. Put initialization inbuild(). build()is called by the framework; do not call it directly.-
Consumers modify state by calling methods on the notifier:
ref.read(myProvider.notifier).myMethod().
Multiple providers, same type#
Riverpod allows multiple providers that expose the same type (e.g. two different Provider<String>). They are independent; no conflict.
Links to other concepts#
- Ref (read, watch, listen, invalidate): riverpod-refs
- Containers / ProviderScope: riverpod-containers
- Auto-dispose: riverpod-auto-dispose
- Family: riverpod-family
- Overrides (testing): riverpod-overrides
- Consumers (widgets): riverpod-consumers