1.6 KiB
1.6 KiB
Riverpod Providers — Reference
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