Upgrading flutter_riverpod 1 to 2
Breaking1.0.4 → 2.6.1Breaking12Platform2Deprecated9New23Changed17Fixed41Other11
BreakingUpgrade verdict
12 breaking changes and 2 platform requirement changes.
In plain terms
- ref.watch(futureProvider.future) can no longer return a SynchronousFuture, which may break Future utilities such as Future.wait.
- The stream helper on FutureProvider is gone.
- You can no longer swap one kind of provider for another kind when overriding.
- Most overrideWithValue methods are gone for now; use overrideWithProvider instead.
Must act Top 5 of 23 that need code or config changes
Dart SDK requirement changed in 2.5.1: >=2.14.0 <3.0.0 → >=2.17.0 <4.0.0.
What you must change
Breaking12
ref.watch(futureProvider.future) can no longer return a SynchronousFuture, which may break Future utilities such as Future.wait.
ref.watchfutureProvider.futureSynchronousFutureFuture.waitRemoves
FutureProvider.stream.FutureProvider.streamoverrideWithProvider can no longer override a provider with a different provider type.overrideWithProviderFutureProviderStreamProviderRemoves all
overrideWithValue methods except Provider.overrideWithValue, temporarily.overrideWithValueProvider.overrideWithValueoverrideWithProviderModifiers such as
provider.future and provider.state are no longer providers and no longer appear in ProviderObserver.provider.futureprovider.stateProviderObserverRemoves the
Reader typedef in favor of Ref.ReaderRefRemoves
ProviderListener in favor of ref.listen.ProviderListenerref.listenRemoves the deprecated
ProviderReference.ProviderReferenceProviders no longer throw
ProviderException when building fails; they rethrow the original exception and stack trace.ProviderExceptionModifiers like
provider.future and provider.notifier can no longer be passed to the dependencies parameter.dependenciesprovider.futureprovider.notifierAsyncError.stackTrace is now a required, non-nullable positional parameter.AsyncError.stackTraceThe
Family type now has a single generic parameter instead of three.FamilyPlatform2
Raises the minimum required Flutter SDK version to 3.0.0.
Raises the minimum required Dart SDK version to 2.17.0.
Deprecations to plan for
Deprecated9
Deprecates all Ref subclasses; use Ref itself instead.
RefDeprecates Ref's type argument; use Ref without its generic parameter.
RefDeprecates Ref members that use Ref's generic, such as Ref.state or Ref.listenSelf; use a Notifier instead.
Ref.stateRef.listenSelfNotifierDeprecates
ProviderScope.parent because it fundamentally does not work.ProviderScope.parentDeprecates the generic parameter of
Family.Familyriverpod_generatorDeprecates StreamProvider.stream in favor of ref.listen and FutureProvider.future.
StreamProvider.streamref.watchref.listenFutureProviderb.futureDeprecates StateProvider.state in favor of ref.watch(stateProvider) or ref.read(stateProvider.notifier).state.
StateProvider.stateref.watchref.readDeprecates provider.overrideWithProvider in favor of provider.overrideWith.
provider.overrideWithProviderprovider.overrideWithDeprecates
AutoDisposeRef.maintainState in favor of the new AutoDisposeRef.keepAlive().AutoDisposeRef.maintainStateAutoDisposeRef.keepAlive()