Skip to content

Upgrading flutter_riverpod 1 to 2

Breaking1.0.4 → 2.6.1Breaking12Platform2Deprecated9New23Changed17Fixed41Other11

BreakingUpgrade verdict

12 breaking changes and 2 platform requirement changes.

  • 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.
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.

Breaking12
ref.watch(futureProvider.future) can no longer return a SynchronousFuture, which may break Future utilities such as Future.wait.
ref.watchfutureProvider.futureSynchronousFutureFuture.wait
Removes FutureProvider.stream.
FutureProvider.stream
overrideWithProvider can no longer override a provider with a different provider type.
overrideWithProviderFutureProviderStreamProvider
Removes all overrideWithValue methods except Provider.overrideWithValue, temporarily.
overrideWithValueProvider.overrideWithValueoverrideWithProvider
Modifiers such as provider.future and provider.state are no longer providers and no longer appear in ProviderObserver.
provider.futureprovider.stateProviderObserver
Removes the Reader typedef in favor of Ref.
ReaderRef
Removes ProviderListener in favor of ref.listen.
ProviderListenerref.listen
Removes the deprecated ProviderReference.
ProviderReference
Providers no longer throw ProviderException when building fails; they rethrow the original exception and stack trace.
ProviderException
Modifiers like provider.future and provider.notifier can no longer be passed to the dependencies parameter.
dependenciesprovider.futureprovider.notifier
AsyncError.stackTrace is now a required, non-nullable positional parameter.
AsyncError.stackTrace
The Family type now has a single generic parameter instead of three.
Family
Platform2
Raises the minimum required Flutter SDK version to 3.0.0.
Raises the minimum required Dart SDK version to 2.17.0.
Deprecated9
Deprecates all Ref subclasses; use Ref itself instead.
Ref
Deprecates Ref's type argument; use Ref without its generic parameter.
Ref
Deprecates Ref members that use Ref's generic, such as Ref.state or Ref.listenSelf; use a Notifier instead.
Ref.stateRef.listenSelfNotifier
Deprecates ProviderScope.parent because it fundamentally does not work.
ProviderScope.parent
Deprecates the generic parameter of Family.
Familyriverpod_generator
Deprecates StreamProvider.stream in favor of ref.listen and FutureProvider.future.
StreamProvider.streamref.watchref.listenFutureProviderb.future
Deprecates StateProvider.state in favor of ref.watch(stateProvider) or ref.read(stateProvider.notifier).state.
StateProvider.stateref.watchref.read
Deprecates provider.overrideWithProvider in favor of provider.overrideWith.
provider.overrideWithProviderprovider.overrideWith
Deprecates AutoDisposeRef.maintainState in favor of the new AutoDisposeRef.keepAlive().
AutoDisposeRef.maintainStateAutoDisposeRef.keepAlive()