Viewing version 2.0.0-dev.6. Open the latest package page.
riverpod
2.0.0-dev.6A simple way to access state from anywhere in your application while robust and testable.
Readme
A state-management library that:
- catches programming errors at compile time rather than at runtime
- removes nesting for listening/combining objects
- ensures that the code is testable
| riverpod | pub package |
|---|---|
| flutter_riverpod | pub package |
| hooks_riverpod | pub package |
Welcome to Riverpod!
This project can be considered as a rewrite of provider to make improvements that would be otherwise impossible.
For learning how to use Riverpod, see its documentation: https://riverpod.dev
Long story short:
-
Declare your providers as global variables:
final counterProvider = StateNotifierProvider((ref) { return Counter(); }); class Counter extends StateNotifier<int> { Counter(): super(0); void increment() => state++; } -
Use them inside your widgets in a compile time safe way. No runtime exceptions!
class Example extends ConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { final count = ref.watch(counterProvider); return Text(count.toString()); } }
See the FAQ if you have questions about what this means for provider.
Migration
With the release of version 1.0.0, the syntax for interacting with providers changed.
See the migration guide for more information
Index
Motivation
If provider is a simplification of InheritedWidgets, then Riverpod is a reimplementation of InheritedWidgets from scratch.
It is very similar to provider in principle, but also has major differences as an attempt to fix the common problems that provider face.
Riverpod has multiple goals. First, it inherits the goals of provider:
- Being able to safely create, observe and dispose states without having to worry about losing the state on widget rebuild.
- Making our objects visible in Flutter's devtool by default.
- Testable and composable
- Improve the readability of InheritedWidgets when we have multiple of them (which would naturally lead to a deeply nested widget tree).
- Make apps more scalable with a unidirectional data flow.
From there, Riverpod goes a few steps beyond:
- Reading objects is now compile-safe. No more runtime exception.
- It makes the provider pattern more flexible, which allows supporting commonly
requested features like:
- Being able to have multiple providers of the same type.
- Disposing the state of a provider when it is no longer used.
- Have computed states
- Making a provider private.
- Simplifies complex object graphs. It is easier to depend on asynchronous state.
- Makes the pattern independent from Flutter
These are achieved by no longer using InheritedWidgets. Instead, Riverpod implements its own mechanism that works in a similar fashion.
For learning how to use Riverpod, see its documentation: https://riverpod.dev
Contributing
Contributions are welcomed!
Here is a curated list of how you can help:
- Report bugs and scenarios that are difficult to implement
- Report parts of the documentation that are unclear
- Fix typos/grammar mistakes
- Update the documentation / add examples
- Implement new features by making a pull-request
FAQ
Why another project when provider already exists?
While provider is largely used and well accepted by the community, it is not perfect either.
People regularly file issues or ask questions about some problems they face, such as:
- Why do I have a
ProviderNotFoundException? - How can I automatically dispose my state when not used anymore?
- How to make a provider that depends on other (potentially complex) providers?
These are legitimate problems, and I believe that something can be improved to fix those.
The issue is, these problems are deeply rooted in how provider works, and fixing those problems is likely impossible without drastic changes to the mechanism of provider.
In a way, if provider is a candle then Riverpod is a lightbulb. They have very similar usages, but we cannot create a lightbulb by improving our candle.
Is it safe to use in production?
Yes.
Riverpod is stable and actively maintained.
Will this get merged with provider at some point?
No. At least not until it is proven that the community likes Riverpod and that it doesn't cause more problems than it solves.
While provider and this project have a lot in common, they do have some major differences. Differences big enough that it would be a large breaking change for users of provider to migrate Riverpod.
Considering that, separating both projects initially sounds like a better compromise.
Will provider be deprecated/stop being supported?
Not in the short term, no.
However, a migration tool is planned to help assist migration from provider to Riverpod.
Sponsors
Changelog
2.0.0-dev.6
- Added
AsyncValue.valueOrNullto obtain the value while ignoring potential errors. - Fixed an issue where
AsyncValue.valuedid not throw if there is an error. - Fix families not applying cacheTime/disposeDelay
- Fixed a bug where an exception may be thrown asynchronously after a
KeepAliveLinkis cancelled.
2.0.0-dev.5
- Fixed a bug where emitting an
AsyncDataafter anAsyncErrorleads toAsyncValue.hasErrorto be true
2.0.0-dev.4
-
Added
ref.listenSelf, for subscribing to changes of a provider within that provider. That can be useful for logging purposes or storing the state of a provider in a DB. -
Added
disposeDelayto allautoDisposeproviders and toProviderContainer/ProviderScope. This configures the amount of time before a provider is disposed when it is not listened. -
Added
container.invalidate(provider)/ref.invalidate(provider)andref.invalidateSelf(). These are similar toref.refreshmethods, but do not immediately rebuild the provider.These methods are safer than
ref.refreshas they can avoid a provider rebuilding twice in a quick succession. -
The duration passed to
cacheTimenow represents the minimum amount of time after the latest change of a provider, instead of the first time a provider built. -
Fixed an issue where providers were incorrectly allowed to depend on themselves, breaking
autoDisposein the process. -
Fixed a memory leak when using
StateProvider.autoDispose's.state -
Fix
ProviderObserver.didDisposeProvidernot executing on provider refresh.
2.0.0-dev.3
When calling ref.listen on a provider, this provider will now properly
rebuild if one of its dependency had changed.
2.0.0-dev.2
-
Deprecated
ref.maintainState=in favor of a newly addedref.keepAlive(). This newref.keepAlive()function is similar tomaintainStatebut better handles cases where we have multiple logics that want to keep the state of a provider alive for some period of time. -
Removed the deprecated
ProviderReference. -
Added
ProviderContainer.cacheTimeandMyProvider.autoDispose(..., cacheTime: duration).cacheTimeis used to keep anautoDisposeprovider alive for at least a minimum amount of time before it gets disposed if not listened. -
Added
ref.onAddListener,ref.onRemoveListener,ref.onCancelandref.onResume. All of which allow performing side-effects when providers are listened or stop being listened.
2.0.0-dev.1
-
Now requires Dart 2.16
-
Breaking Providers no-longer throw a
ProviderExceptionif an exception was thrown while building their value.
Instead, they will rethrow the thrown exception and its stacktrace. -
Removed
AsyncValue'sisError/isData -
Added new functionalities to
AsyncValue:hasError,hasData,copyWithPrevious -
Added
provider.selectAsync, which allows to both await an async value while also filtering rebuilds. -
When a provider emits an
AsyncErrorfollowed by anAsyncData, theAsyncDataemitted will now contain the latest error/stackTrace too. -
Fixed a cast error when overriding a provider with a more specific provider type (#1100)
-
Fixed a bug where
onDisposelisteners could be executed twice under certain conditions when usingautoDispose.
2.0.0-dev.0
-
Breaking After a provider has emitted an
AsyncValue.dataorAsyncValue.error, that provider will no longer emit anAsyncValue.loading.
Instead, it will re-emit the latest value, but with the propertyAsyncValue.isRefreshingto true.This allows the UI to keep showing the previous data/error when a provider is being refreshed.
-
Adding
isLoading,isError,isDataandasErrortoAsyncValue. Those getters allow interacting withAsyncValuewithout having to rely on pattern matching. -
Fixed an issue where refreshing a
provider.future/provider.streamdid work properly -
Fixed false positive with
ref.watchasserts
1.0.3
Removed an assert preventing from overriding the same provider/family
multiple times on a ProviderScope/ProviderContainer.
1.0.2
Fixed a null exception on web
1.0.1
Improved the performance of the assert which verifies that providers properly
respect their dependencies variable.
1.0.0
Riverpod is now stable!
General changes
-
Breaking:
ProviderContainer.debugProviderValuesandProviderContainer.debugProviderElementsare removed. You can now instead useProviderContainer.getAllProviderElements. -
Increased minimum SDK version to 2.14.0
-
Breaking The return value when reading a
StateProviderchanged. Before, doingref.read(someStateProvider)would return theStateControllerinstance.
Now, this will only return the state of theStateController.
This new behaviour matchesStateNotifierProvider.For a simple migration, the old behavior is available by writing
ref.read(someStateProvider.state). -
Added
ref.listenfor triggering actions inside providers/widgets when a provider changes.It can be used to listen to another provider without recreating the provider state:
final counterProvider = StateNotifierProvider<Counter, int>(...); final anotherProvider = Provider<T>((ref) { ref.listen<int>(counterProvider, (previous, count) { print('counter changed from $previous to $count'); }); });Alternatively, it can be used by widgets to show modals/dialogs:
final counterProvider = StateNotifierProvider<Counter, int>(...); class Example extends ConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { ref.listen<int>(counterProvider, (previous, count) { showDialog(...); }); } } -
It is now possible to "await" all providers that emit an
AsyncValue(previously limited toFutureProvider/StreamProvider). This includes cases where aStateNotifierProviderexposes anAsyncValue:class MyAsyncStateNotifier extends StateNotifier<AsyncValue<MyState>> { MyAsyncStateNotifier(): super(AsyncValue.loading()) { // TODO fetch some data and update the state when it is obtained } } final myAsyncStateNotifierProvider = StateNotifierProvider<MyAsyncStateNotifier, AsyncValue<MyState>>((ref) { return MyAsyncStateNotifier(); }); final someFutureProvider = FutureProvider((ref) async { MyState myState = await ref.watch(myAsyncStateNotifierProvider.future); }); -
Deprecated
StreamProvider.lastin favor ofStreamProvider.future. -
StreamProvider.future,StreamProvider.streamandFutureProvider.futurenow expose a future/stream that is independent from how many times the associated provider "rebuilt":- if a
StreamProviderrebuild before its stream emitted any value,StreamProvider.futurewill resolve with the first value of the new stream instead. - if a
FutureProviderrebuild before its future completes,FutureProvider.futurewill resolve with the result of the new future instead.
- if a
-
You can now override any provider with any other provider, as long as the value that they expose matches. For example, it is possible to override a
StreamProvider<Model>with aProvider<AsyncValue<Model>>. -
ref.onDisposenow calls the dispose function as soon as one of the provider's dependencies is known to have changed -
Providers can now call
ref.refreshto refresh a provider, instead of having to doref.container.refresh. -
Providers no longer wait until their next read to recompute their state if one of their dependencies changed and they have listeners.
-
Added
ProviderContainer.pump, a utility to easily "await" until providers notify their listeners or are disposed. -
fixed an issue when using both
familyandautoDisposethat could lead to an inconsistent state
Unified the syntax for interacting with providers
-
ProviderReferenceis deprecated in favor ofRef. -
ref.watchnow supportsmyProvider.select((value) => ...). This allows filtering rebuilds:final userProvider = StateNotifierProvider<UserController, User>(...); final anotherProvider = Provider((ref) { // With this syntax, the Consumer will not rebuild if `userProvider` // emits a new User but its "name" didn't change. bool userName = ref.watch(userProvider.select((user) => user.name)); }); -
Breaking:
ProviderObserver.didUpdateProvidernow receives both the previous and new value. -
Breaking:
ProviderObserver.mayHaveChangedis removed. -
Breaking:
Family.overrideWithProvidernow must create a provider:final family = Provider.family<State, Arg>(...); family.overrideWithProvider( (Arg arg) => Provider<State>((ref) => ...) ); -
All providers now receive a custom subclass of
ProviderRefBaseas a parameter:Provider<T>((ProviderRef<T> ref) {...}); FutureProvider<T>((FutureProviderRef<T> ref) {...}); StateProvider<T>((StateProviderRef<T> ref) {...});That allows providers to implement features that is not shared with other providers.
-
Provider,FutureProviderandStreamProvider'srefnow have astateproperty, which represents the currently exposed value. Modifying it will notify the listeners:Provider<int>((ref) { ref.listen(onIncrementProvider, (_) { ref.state++; }); return 0; }); -
StateProvider'srefnow has acontrollerproperty, which allows the provider to access theStateControllerexposed.
-
-
Breaking:
ProviderReference.mountedis removed. You can implement something similar usingonDispose:Provider<T>((ref) { var mounted = true; ref.onDispose(() => mounted = false); });
All providers can now be scoped.
-
Breaking:
ScopedProvideris removed.
To migrate, changeScopedProviders toProviders. -
All providers now come with an extra named parameter called
dependencies. This parameter optionally allows defining the list of providers/families that this new provider depends on:final a = Provider(...); final b = Provider((ref) => ref.watch(a), dependencies: [a]);By doing so, this will tell Riverpod to automatically override
bifagets overridden.
Updated AsyncValue:
-
Breaking
AsyncValue.copyWithis removed -
Breaking
AsyncValue.error(..., stacktrace)is now a named parameter instead of postional parameter. -
Deprecated
AsyncValue.datain favor ofAsyncValue.value -
Allowed
AsyncData,AsyncErrorandAsyncLoadingto be extended -
Added
AsyncValue.whenOrNull, similar towhenOrElsebut instead of an "orElse" parameter, returnsnull. -
Added
AsyncValue.value, which allows reading the value without handling loading/error states. -
AsyncErrorcan now be instantiated withconst. -
Added
StateController.update, to simplify updating the state from the previous state:final provider = StateController((ref) => 0); ... ref.read(provider).update((state) => state + 1); -
It is no longer allowed to use
ref.watchorref.readinside a selector:provider.select((value) => ref.watch(something)); // KO, cannot use ref.watch inside selectors -
FutureProvider now creates a
FutureOr<T>instead of aFuture<T>.
That allows bypassing the loading state in the event where a value was synchronously available.
Bug fixes
- Fixed a bug where widgets were not rebuilding in release mode under certain conditions
- FIX: StreamProvider.last no longer throws a StateError when no value were emitted (#296).
- fixed an issue where when chaining providers, widgets may re-render a frame late, potentially causing a flicker. (see #648)
1.0.0-dev.10
Fixed a bug where reading a provider within a consumer could throw (#796)
1.0.0-dev.9
Fix an issue where *Provider.autoDispose were not able to specify the
dependencies parameter.
1.0.0-dev.8
Future/StreamProvider
-
FutureProvider now creates a
FutureOr<T>instead of aFuture<T>That allows bypassing the loading state in the event where a value was synchronously available. -
During loading and error states,
FutureProviderandStreamProvidernow expose the latest value throughAsyncValue.
That allows UI to show the previous data while some new data is loading, inatead of showing a spinner:final provider = FutureProvider<User>((ref) async { ref.watch(anotherProvider); // may cause `provider` to rebuild return fetchSomething(); }) ... Widget build(context, ref) { return ref.watch(provider).when( error: (err, stack, _) => Text('error'), data: (user) => Text('Hello ${user.name}'), loading: (previous) { if (previous is AsyncData<User>) { return Text('loading ... (previous: ${previous.value.name})'}); } return CircularProgressIndicator(); } ); }
AsyncValue
- Breaking
AsyncValue.copyWithis removed - Breaking
AsyncValue.error(..., stacktrace)is now a named parameter instead of postional parameter. - Breaking
AsyncValue.when(loading: )and ``AsyncValue.when(error: )(andwhen` variants) now receive an extra "previous" parameter. - Deprecated
AsyncValue.datain favor ofAsyncValue.value - Allowed
AsyncData,AsyncErrorandAsyncLoadingto be extended - Added
AsyncValue.whenOrNull, similar towhenOrElsebut instead of an "orElse" parameter, returnsnull. - Added
AsyncValue.value, which allows reading the value without handling loading/error states. AsyncErrorcan now be instantiated withconst.AsyncLoadingandAsyncErrornow optionally includes the previous state.
General
-
Breaking All
overrideWithProvidermethods are removed.
To migrate, instead useoverrideWithValue. -
All providers now come with an extra named parameter called
dependencies. This parameter optionally allows defining the list of providers/families that this new provider depends on:final a = Provider(...); final b = Provider((ref) => ref.watch(a), dependencies: [a]);By doing so, this will tell Riverpod to automatically override
bifagets overridden. -
Added
StateController.update, to simplify updating the state from the previous state:final provider = StateController((ref) => 0); ... ref.read(provider).update((state) => state + 1); -
It is no longer allowed to use
ref.watchorref.readinside a selector:provider.select((value) => ref.watch(something)); // KO, cannot user ref.watch inside selectors
Bug-fixes
- fixed a bug where providers were rebuilding even when not being listened to
- fixed
ref.listennow working when downcasting the value of a provider. - fixed a bug where disposing a scoped
ProviderContainercould cause otherProviderContainers to stop working. - fixed an issue where conditionally depending on an "autoDispose" provider may not properly dispose of it (see #712)
- fixed an issue where when chaining providers, widgets may re-render a frame late, potentially causing a flicker. (see #648)
1.0.0-dev.7
- Fixed
ProviderObservernot working when modifying aStateProvider. - Fixed a bug where scoped provider were potentially not disposed
- Fixed a bug where widgets were not rebuilding in release mode under certain conditions
1.0.0-dev.6
- FIX: StreamProvider.last no longer throws a StateError when no value were emitted (#296).
- Re-enabled debug assertions that were temporarily disabled by previous dev versions.
- Allows families to be scoped/overridden
- Fixed bugs with
ref.refreshnot working on some providers - renamed
ProviderBase.recreateShouldNotifytoupdateShouldNotify
1.0.0-dev.5
Fixed an issue where provider listeners could not be called properly.
1.0.0-dev.3
Fixed various issues related to scoped providers.
1.0.0-dev.2
- All providers can now be scoped.
- breaking:
ScopedProvideris removed. To migrate, changeScopedProviders toProviders.
1.0.0-dev.1
- Add missing exports (see #532)
1.0.0-dev.0
-
ref.watchnow supportmyProvider.select((value) => ...). This allows filtering rebuilds:final userProvider = StateNotifierProvider<UserController, User>(...); final anotherProvider = Provider((ref) { // With this syntax, the Consumer will not rebuild if `userProvider` // emits a new User but its "name" didn't change. bool userName = ref.watch(userProvider.select((user) => user.name)); }); -
Breaking:
Family.overrideWithProvidernow must create a provider:final family = Provider.family<State, Arg>(...); family.overrideWithProvider( (Arg arg) => Provider<State>((ref) => ...) ); -
Breaking:
ProviderObserver.didUpdateProvidernow receives both the previous and new value. -
Breaking:
ProviderObserver.mayHaveChangedis removed. -
Added
ref.listen, used to listen to another provider without recreating the provider state:final counter = StateNotifierProvider<Counter, int>(...); final anotherProvider = Provider<T>((ref) { ref.listen<int>(counter, (count) { print('counter change: $count'); }); }); -
ProviderReferenceis deprecated in favor ofProviderRefBase. -
All providers now receive a custom subclass of
ProviderRefBaseas a parameter:Provider<T>((ProviderRef<T> ref) {...}); FutureProvider<T>((FutureProviderRef<T> ref) {...}); StateProvider<T>((StateProviderRef<T> ref) {...});That allows providers to implement features that is not shared with other providers.
-
Provider,FutureProviderandStreamProvider'srefnow have astateproperty, which represents the currently exposed value. Modifying it will notify the listeners:Provider<int>((ref) { ref.listen(onIncrementProvider, (_) { ref.state++; }); return 0; }); -
StateProvider'srefnow has acontrollerproperty, which allows the provider to access theStateControllerexposed.
-
-
Breaking:
ProviderReference.mountedis removed. You can implement something similar usingonDispose:Provider<T>((ref) { var mounted = true; ref.onDispose(() => mounted = false); }); -
Breaking:
ProviderContainer.debugProviderValuesandProviderContainer.debugProviderElementsare removed. You can now instead useProviderContainer.getAllProviderElements. -
StreamProvider.last,StreamProvider.streamandFutureProvider.futurenow expose a future/stream that is independent from how many times the associated provider "rebuilt":- if a
StreamProviderrebuild before its stream emitted any value,StreamProvider.lastwill resolve with the first value of the new stream instead. - if a
FutureProviderrebuild before its future completes,FutureProvider.futurewill resolve with the result of the new future instead.
- if a
-
You can now override any provider with any other provider, as long as the value that they expose matches. For example, it is possible to override a
StreamProvider<Model>with aProvider<AsyncValue<Model>>. -
ref.onDisposenow calls the dispose function as soon as one of the provider's dependency is known to have changed -
Providers can now call
ref.refreshto refresh a provider, instead of having to doref.container.refresh. -
Providers no longer wait until their next read to recompute their state if one of their dependencies changed and they have listeners.
-
Added
ProviderContainer.pump, a utility to easily "await" until providers notify their listeners or are disposed. -
fixed an issue when using both
familyandautoDisposethat could lead to an inconsistent state
0.14.0+3
Removed an assert that could cause issues when an application is partially migrated to null safety.
0.14.0+1
- Re-added
StateProvider.overrideWithValue/StateProvider.overrideWithProviderthat were unvoluntarily removed.
0.14.0
-
BREAKING CHANGE The
Listener/LocatorMixintypedefs are removed as the former could cause a name conflict with the widget namedListenerand the latter is not supported when using Riverpod. -
BREAKING CHANGE The syntax for using
StateNotifierProviderwas updated. Before:class MyStateNotifier extends StateNotifier<MyModel> {...} final provider = StateNotifierProvider<MyStateNotifier>((ref) => MyStateNotifier()); ... Widget build(context, watch) { MyStateNotifier notifier = watch(provider); MyModel model = watch(provider.state); }After:
class MyStateNotifier extends StateNotifier<MyModel> {...} final provider = StateNotifierProvider<MyStateNotifier, MyModel>>((ref) => MyStateNotifier()); ... Widget build(context, watch) { MyStateNotifier notifier = watch(provider.notifier); MyModel model = watch(provider); }See also https://github.com/rrousselGit/river_pod/issues/341 for more information.
-
BREAKING CHANGE It is no longer possible to override
StreamProvider.stream/lastandFutureProvider.future. -
feat: Calling
ProviderContainer.disposemultiple time no longer throws. This simplifies the tear-off logic of tests. -
feat: Added
ChangeNotifierProvider.notifierandStateProvider.notifierThey allow obtaining the notifier associated with the provider, without causing widgets/providers to rebuild when the state updates. -
fix: overriding a
StateNotifierProvider/ChangeNotifierProviderwithoverrideWithValuenow correctly listens to the notifier.
0.13.1
- Fixed a bug where overriding a
FutureProviderwith an error value could cause tests to fail (see https://github.com/rrousselGit/river_pod/issues/355)
0.13.0
- stable null-safety release
ProviderObservercan now have a const constructor- Added the mechanism for state-inspection using the Flutter devtool
- loosened the version constraints of
freezed_annotation - deprecated
import 'riverpod/all.dart'. Now everything is available withriverpod/riverpod.dart. - Fixed a but where listening to
StreamProvider.lastcould result in aStateError(#217)
0.13.0-nullsafety.3
- deprecated
import 'riverpod/all.dart'. Now everything is available withriverpod/riverpod.dart.
0.13.0-nullsafety.1
- Fixed a but where listening to
StreamProvider.lastcould result in aStateError(#217)
0.13.0-nullsafety.0
Migrated to null-safety
0.12.2
- Exported
AutoDisposeProviderRefBase
0.12.1
- Fixed an remaining memory leak related to StreamProvider (see also https://github.com/rrousselGit/river_pod/issues/193)
0.12.0
- Breaking FutureProvider and StreamProvider no longer supports
nullas a valid value. - Fixed a memory leak with StreamProvider (see also https://github.com/rrousselGit/river_pod/issues/193)
0.11.2
- Fixed a bug where providers (usually ScopedProviders) did not dispose correctly (see also https://github.com/rrousselGit/river_pod/issues/154).
0.11.0
package:riverpod/riverpod.dartnow exportsStateNotifier- Marked the providers with
@sealedso that the IDE warns against implementing/subclassing providers. - Fix mistakes in
AsyncValue.guard's documentation (thanks @mono0926) - Loosened the version constraints of
freezed_annotationto support0.12.0
0.10.0
-
Fixed a bug where the state of a provider may be disposed when it shouldn't be disposed.
-
Added a way to import the implementation class of providers with modifiers, such as
AutoDisposeProvider.This is useful if you want to use Riverpod with the lint
always_specify_types:import 'package:riverpod/all.dart'; final AutoDisposeStateProvider<int> counter = StateProvider.autoDispose<int>((ProviderRefBase ref) { return 0; });If you do not use this lint, prefer using the default import instead, to not pollute your auto-complete.
0.8.0
- Renamed
ProviderContainer.debugProviderStatestoProviderContainer.debugProviderElements - Fixed a bug where updating
ProviderScope.overridesmay cause an exception for no reason (see https://github.com/rrousselGit/river_pod/issues/107)
0.7.0
-
ref.watchon non ".autoDispose" providers can no longer read ".autoDispose" providers.For more info, see http://riverpod.dev/docs/concepts/modifiers/auto_dispose#the-argument-type-autodisposeprovider-cant-be-assigned-to-the-parameter-type-alwaysaliveproviderbase
-
ScopedProvidernow acceptsnullas a function:final example = ScopedProvider<int>(null);Which is equivalent to:
final example = ScopedProvider<int>((watch) => throw UnimplementedError('')); -
Fixed a bug where
context.refreshmay not work properly if the widget tree contains multipleProviderScope.
0.6.1
- Fixed a bug where when disposing
ProviderContainer, providers may be disposed in an incorrect order. - Improved the performances of reading providers by 25%
0.6.0
-
Merged
ComputedandProvider. Now, all providers have the ability to rebuild their state when one of the object they listen changed.To migrate, change:
final provider = Provider(...); final example = Computed((watch) { final value = watch(provider); return value; });into:
final provider = Provider(...); final example = Provider((ref) { final value = ref.watch(provider); return value; }); -
Computed(nowProvider) no longer deeply compare collections to avoid rebuilds. Comparing the content of lists is quite expensive and actually rarely useful. Now, a simple==comparison is used. -
Renamed
ProviderStateOwnertoProviderContainer -
Renamed
ProviderStateOwnerObservertoProviderObserver -
It is no longer possible to override a provider anywhere in the widget tree. Providers can only be overridden in the top-most
ProviderContainer. -
Providers can now read values which may change over time using
ref.readandref.watch. When usingref.watch, if the value obtained changes, this will cause the provider to re-create its state. -
It is no longer possible to add
ProviderObserveranywhere in the widget tree. They can be added only on the top-mostProviderContainer. -
Added
ProviderContainer.refresh(provider). This method allows forcing the refresh of a provider, which can be useful for things like "retry on error" or "pull to refresh".
-
ref.read(StreamProvider<T>)no longer returns aStream<T>but anAsyncValue<T>Before:final streamProvider = StreamProvider<T>(...); final example = Provider((ref) { Stream<T> stream = ref.read(streamProvider); });After:
final streamProvider = StreamProvider<T>(...); final example = Provider((ref) { Stream<T> stream = ref.watch(streamProvider.steam); }); -
ref.read(FutureProvider<T>)no longer returns aFuture<T>but anAsyncValue<T>Before:
final futureProvider = FutureProvider<T>(...); final example = Provider((ref) { Future<T> future = ref.read(futureProvider); });After:
final futureProvider = FutureProvider<T>(...); final example = Provider((ref) { Future<T> future = ref.watch(futureProvider.future); }); -
Removed
ref.dependOn. You can now useref.read/ref.watchto achieve the same effect.Before:
final streamProvider = StreamProvider<T>(...); final example = Provider((ref) { Future<T> last = ref.dependOn(streamProvider).last; });After:
final streamProvider = StreamProvider<T>(...); final example = Provider((ref) { Future<T> last = ref.watch(streamProvider.last); }); -
Provider.readOwner(ProviderStateOwner)is changed intoProviderContainer.read(Provider) -
Provider.watchOwner(ProviderStateOwner, (value) {})is changed into:ProviderContainer container; final provider = Provider((ref) => 0); final subscription = container.listen( provider, mayHaveChanged: (sub) {}, didChange: (sub) {}. ); subscription.close(); -
MyProvider.family.autoDisposenow correctly free both the arguments and the associated providers from memory when the provider is no longer listened to.
- Added
ScopedProvider, a new kind of provider that can be overridden anywhere in the widget tree. Normal providers cannot read aScopedProvider.
0.5.1
- Fixed the documentation of
StateNotifierProviderincorrectly showing the documentation ofStreamProvider. - Improve the documentation of
StateProvider.
0.5.0
- Changed
ComputedFamilyintoComputed.family - Added [AsyncValue.guard](https://pub.dev/documentation/riverpod/latest/riverpod/AsyncValue/guard.html to simplify transforming a Future into an AsyncValue.
- Improved the documentation of the different providers
0.4.0
Changed the syntax of "AutoDispose*" and "*Family" to use a syntax similar to named constructors instead.
Before:
final myProvider = AutoDisposeStateNotifierProviderFamily<MyStateNotifier, int>((ref, id) {
return MyStateNotifier(id: id);
});
After:
final myProvider = StateNotifierProvider.autoDispose.family<MyStateNotifier, int>((ref, id) {
return MyStateNotifier(id: id);
});
The behavior is the same. Only the syntax changed.
0.3.0
-
Added
AsyncValue.whenData, syntax sugar forAsyncValue.whento handle only thedatacase and do nothing for the error/loading cases. -
Fixed a bug that caused [Computed] to crash if it stopped being listened to then was listened to again.
0.2.1
Computednow correctly unsubscribe to a provider when their function stops using a provider.
0.2.0
ref.readis renamed asref.dependOn- Deprecated
ref.dependOn(streamProvider).streamandref.dependOn(futureProvider).futurein favor of a universalref.dependOn(provider).value. - added
ref.read(provider), syntax sugar forref.dependOn(provider).value.
0.1.0
Initial release
Installing
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add 'riverpod:2.0.0-dev.6'pubspec.yaml
name: riverpod
description: >
A simple way to access state from anywhere in your application while robust
and testable.
version: 2.0.0-dev.6
homepage: https://riverpod.dev
repository: https://github.com/rrousselGit/river_pod
environment:
sdk: ">=2.14.0 <3.0.0"
dependencies:
collection: ^1.15.0
meta: ^1.3.0
stack_trace: ^1.10.0
state_notifier: ^0.7.0
dev_dependencies:
build_runner: ^2.0.0
expect_error: ^1.0.0
freezed: ^0.14.0
mockito: ^5.0.0
test: ^1.16.0
trotter: ^2.0.0-dev.1Version history
| Version | Published | Archive | SHA-256 |
|---|---|---|---|
| 0.0.1-pre | Cached · Upstream SHA-256 matched | Download | 4293ac1d…c5e806 |
| 0.0.1-pre+1 | Cached · Upstream SHA-256 matched | Download | 303e5601…245d0a |
| 0.1.0 | Cached · Upstream SHA-256 matched | Download | 1a93b2a5…4a2699 |
| 0.2.0 | Cached · Upstream SHA-256 matched | Download | 1e67d29d…38ae96 |
| 0.2.1 | Cached · Upstream SHA-256 matched | Download | 35fc5b2f…6ad2c9 |
| 0.3.0 | Cached · Upstream SHA-256 matched | Download | 21ed42e4…e54061 |
| 0.4.0 | Cached · Upstream SHA-256 matched | Download | 922009d6…170583 |
| 0.5.0 | Cached · Upstream SHA-256 matched | Download | b0c51f47…02b3b8 |
| 0.5.1 | Cached · Upstream SHA-256 matched | Download | a424df1b…399bb7 |
| 0.6.0-dev | Cached · Upstream SHA-256 matched | Download | ce575b60…4f3294 |
| 0.6.0-dev+1 | Cached · Upstream SHA-256 matched | Download | 7fad2e5f…a1059a |
| 0.6.0-dev+2 | Cached · Upstream SHA-256 matched | Download | fdd66c35…22e382 |
| 0.6.0-dev+3 | Cached · Upstream SHA-256 matched | Download | 54f00828…a554cb |
| 0.6.0 | Cached · Upstream SHA-256 matched | Download | 8d04f41d…8f265d |
| 0.6.0+1 | Cached · Upstream SHA-256 matched | Download | 8e29da64…0a519f |
| 0.6.1 | Cached · Upstream SHA-256 matched | Download | 62162ffb…4e61cd |
| 0.7.0 | Cached · Upstream SHA-256 matched | Download | fb11b1c7…51bec2 |
| 0.8.0 | Cached · Upstream SHA-256 matched | Download | c727b646…1352ce |
| 0.10.0 | Cached · Upstream SHA-256 matched | Download | 9ab76912…948d47 |
| 0.11.0 | Cached · Upstream SHA-256 matched | Download | f0a45611…152874 |
| 0.11.2 | Cached · Upstream SHA-256 matched | Download | 6adcf330…a03e28 |
| 0.12.0 | Cached · Upstream SHA-256 matched | Download | 57e82963…e55b92 |
| 0.12.1 | Cached · Upstream SHA-256 matched | Download | 38473ef0…09c05c |
| 0.12.2 | Cached · Upstream SHA-256 matched | Download | de0cb4aa…5c2d70 |
| 0.12.3 | Cached · Upstream SHA-256 matched | Download | 83e9a709…deceb5 |
| 0.12.4 | Cached · Upstream SHA-256 matched | Download | 69e07407…33e85c |
| 0.13.0-nullsafety.0 | Cached · Upstream SHA-256 matched | Download | f2464614…088a95 |
| 0.13.0-nullsafety.1 | Cached · Upstream SHA-256 matched | Download | 1aff218f…d34efa |
| 0.13.0-nullsafety.3 | Cached · Upstream SHA-256 matched | Download | acda31a7…f13e6e |
| 0.13.0 | Cached · Upstream SHA-256 matched | Download | 05f0e1bd…1c5cc2 |
| 0.13.1 | Cached · Upstream SHA-256 matched | Download | ca4ef57a…3c79c6 |
| 0.14.0 | Cached · Upstream SHA-256 matched | Download | 982e5733…803c17 |
| 0.14.0+1 | Cached · Upstream SHA-256 matched | Download | af9d98fb…1857e7 |
| 0.14.0+3 | Cached · Upstream SHA-256 matched | Download | 13cbe0e1…4eae07 |
| 1.0.0-dev.0 | Cached · Upstream SHA-256 matched | Download | 9c9b6700…e4217b |
| 1.0.0-dev.1 | Cached · Upstream SHA-256 matched | Download | da5b2bc2…a35c8a |
| 1.0.0-dev.2 | Cached · Upstream SHA-256 matched | Download | 70455873…857521 |
| 1.0.0-dev.3 | Cached · Upstream SHA-256 matched | Download | 5a25043f…6ba9fe |
| 1.0.0-dev.5 | Cached · Upstream SHA-256 matched | Download | 919e02ea…a060af |
| 1.0.0-dev.6 | Cached · Upstream SHA-256 matched | Download | b663ec2f…6630f8 |
| 1.0.0-dev.7 | Cached · Upstream SHA-256 matched | Download | 0f4a606a…cfa4b3 |
| 1.0.0-dev.8 | Cached · Upstream SHA-256 matched | Download | 7bbbd1cc…a1a829 |
| 1.0.0-dev.9 | Cached · Upstream SHA-256 matched | Download | 75a6d8e3…f72d13 |
| 1.0.0-dev.10 | Cached · Upstream SHA-256 matched | Download | 38d86325…a12cc2 |
| 1.0.0 | Cached · Upstream SHA-256 matched | Download | 8538f67c…37c771 |
| 1.0.1 | Cached · Upstream SHA-256 matched | Download | ea94268d…35fd13 |
| 1.0.2 | Cached · Upstream SHA-256 matched | Download | cfd3d6bf…85cb17 |
| 1.0.3 | Cached · Upstream SHA-256 matched | Download | e7f09715…28217d |
| 1.0.3+1 | Cached · Upstream SHA-256 matched | Download | 98f9ac54…3e4485 |
| 2.0.0-dev.0 | Cached · Upstream SHA-256 matched | Download | cf188b1a…31d37e |
| 2.0.0-dev.1 | Cached · Upstream SHA-256 matched | Download | 0de700b4…d64431 |
| 2.0.0-dev.2 | Cached · Upstream SHA-256 matched | Download | 16b8fee4…afd455 |
| 2.0.0-dev.3 | Cached · Upstream SHA-256 matched | Download | b4fec8df…c12d47 |
| 2.0.0-dev.4 | Cached · Upstream SHA-256 matched | Download | 190ecb07…a32925 |
| 2.0.0-dev.5 | Cached · Upstream SHA-256 matched | Download | 90de2f33…329efe |
| 2.0.0-dev.6 | Cached · Upstream SHA-256 matched | Download | 04716177…2e056f |
| 2.0.0-dev.7 | Cached · Upstream SHA-256 matched | Download | 2eae8f07…f5973d |
| 2.0.0-dev.8 | Cached · Upstream SHA-256 matched | Download | d4e6ac33…31c2c6 |
| 2.0.0-dev.9 | Cached · Upstream SHA-256 matched | Download | ccf59580…81ab2c |
| 2.0.0 | Cached · Upstream SHA-256 matched | Download | 427d64b8…e524a6 |
| 2.0.1 | Cached · Upstream SHA-256 matched | Download | d52ac0cc…09cc21 |
| 2.0.2 | Cached · Upstream SHA-256 matched | Download | 45b63637…cd2bac |
| 2.1.0 | Cached · Upstream SHA-256 matched | Download | ce7f4a28…866156 |
| 2.1.1 | Cached · Upstream SHA-256 matched | Download | 899cd099…1b29f9 |
| 2.1.2 | Cached · Upstream SHA-256 matched | Download | 74bb148e…5d5be8 |
| 2.1.3 | Cached · Upstream SHA-256 matched | Download | 0f43c64f…56e2c4 |
| 2.2.0 | Cached · Upstream SHA-256 matched | Download | 59a48de9…9e8c4b |
| 2.3.0 | Cached · Upstream SHA-256 matched | Download | c5aea6c3…76cd25 |
| 2.3.1 | Cached · Upstream SHA-256 matched | Download | 7da5a0fe…85bfa5 |
| 2.3.2 | Cached · Upstream SHA-256 matched | Download | b0fbf792…cd8dc4 |
| 2.3.3 | Cached · Upstream SHA-256 matched | Download | fc63714d…14b585 |
| 2.3.4 | Cached · Upstream SHA-256 matched | Download | 77ab3bcd…df6ae5 |
| 2.3.5 | Cached · Upstream SHA-256 matched | Download | ec564106…8854b2 |
| 2.3.6 | Cached · Upstream SHA-256 matched | Download | 80e48beb…e2d8ef |
| 2.3.7 | Cached · Upstream SHA-256 matched | Download | b0657b5b…ade793 |
| 2.3.9 | Cached · Upstream SHA-256 matched | Download | 52b2937f…9a287c |
| 2.3.10 | Cached · Upstream SHA-256 matched | Download | 6c0a2c30…cb3f6a |
| 2.4.0 | Cached · Upstream SHA-256 matched | Download | a600120d…f67d22 |
| 2.4.1 | Cached · Upstream SHA-256 matched | Download | ff676bd8…7cc914 |
| 2.4.3 | Cached · Upstream SHA-256 matched | Download | 494bf2cf…f5e208 |
| 2.4.4 | Cached · Upstream SHA-256 matched | Download | 2af3d127…d878b1 |
| 2.4.5 | Cached · Upstream SHA-256 matched | Download | 2e843150…b63d55 |
| 2.4.6 | Cached · Upstream SHA-256 matched | Download | 01fa385a…58d4b2 |
| 2.4.7 | Cached · Upstream SHA-256 matched | Download | f003970b…840cf4 |
| 2.4.8 | Cached · Upstream SHA-256 matched | Download | 08451ddb…478848 |
| 2.4.9 | Cached · Upstream SHA-256 matched | Download | 942999ee…550b11 |
| 2.5.0 | Cached · Upstream SHA-256 matched | Download | 548e2192…ba3589 |
| 2.5.1 | Cached · Upstream SHA-256 matched | Download | f21b32ff…1dfa4d |
| 2.5.3 | Cached · Upstream SHA-256 matched | Download | c86fedfb…f7b5c9 |
| 2.6.0 | Cached · Upstream SHA-256 matched | Download | bd6e656a…744c75 |
| 2.6.1 | Cached · Upstream SHA-256 matched | Download | 59062512…a72959 |
| 3.0.0-dev.0 | Cached · Upstream SHA-256 matched | Download | 41918a79…d2b723 |
| 3.0.0-dev.1 | Cached · Upstream SHA-256 matched | Download | 2aaf880d…dcbc85 |
| 3.0.0-dev.2 | Cached · Upstream SHA-256 matched | Download | 5bf1b037…48f915 |
| 3.0.0-dev.3 | Cached · Upstream SHA-256 matched | Download | 0f41a697…44eaf2 |
| 3.0.0-dev.12 | Cached · Upstream SHA-256 matched | Download | 114b10d3…b9700e |
| 3.0.0-dev.13 | Cached · Upstream SHA-256 matched | Download | 67aac6ba…429c52 |
| 3.0.0-dev.14 | Cached · Upstream SHA-256 matched | Download | daed1b04…173d63 |
| 3.0.0-dev.15 | Cached · Upstream SHA-256 matched | Download | 4369c46c…2a37f9 |
| 3.0.0-dev.16 | Cached · Upstream SHA-256 matched | Download | 0aa816ff…628f31 |
| 3.0.0-dev.17 | Cached · Upstream SHA-256 matched | Download | 82507cfb…e91b8e |
| 3.0.0-dev.18 | Cached · Upstream SHA-256 matched | Download | a64ca86e…2c85a6 |
| 3.0.0 | Cached · Upstream SHA-256 matched | Download | 135723ec…be6d05 |
| 3.0.1 | Cached · Upstream SHA-256 matched | Download | b21446f0…ce4810 |
| 3.0.2 | Cached · Upstream SHA-256 matched | Download | f51e4fb8…81f564 |
| 3.0.3 | Cached · Upstream SHA-256 matched | Download | c406de02…16aa59 |
| 3.1.0 | Cached · Upstream SHA-256 matched | Download | 16ff608d…d4935a |
| 3.2.0 | Cached · Upstream SHA-256 matched | Download | 90266762…ec66f1 |
| 3.2.1 | Cached · Upstream SHA-256 matched | Download | 8c22216b…279f83 |
| 3.3.2-dev.1 | Cached · Upstream SHA-256 matched | Download | b3dd973b…d44461 |
| 3.3.2-dev.2 | Cached · Upstream SHA-256 matched | Download | da723396…042b3f |
| 3.3.2 | Cached · Upstream SHA-256 matched | Download | 17100416…126c76 |
| 3.4.0 | Cached · Upstream SHA-256 matched | Download | b4184653…48d786 |
| 3.4.1 | Cached · Upstream SHA-256 matched | Download | ccd1d45f…21b436 |
| 3.4.2 | Cached · Upstream SHA-256 matched | Download | 84351b34…8e50f1 |
| 3.4.3 | Cached · Upstream SHA-256 matched | Download | 484dfc87…ba4b7a |
Dependencies
collection "^1.15.0"
meta "^1.3.0"
stack_trace "^1.10.0"
state_notifier "^0.7.0"