Skip to content

Upgrading flutter_riverpod 0.14 to 1

Breaking0.14.0+3 → 1.0.4Breaking17Platform1Deprecated6New19Changed9Fixed19Other1

BreakingUpgrade verdict

16 breaking changes and a platform requirement change.

  • Two debugging helpers on the provider container are gone. Use the new single method to list provider elements.
  • The mounted flag is gone, so track disposal yourself with a local variable and onDispose.
  • A method that observers could override no longer exists.
  • ScopedProvider no longer exists, so switch those to regular providers.
Top 5 of 22 that need code or config changes

Dart SDK requirement changed in 1.0.0: >=2.12.0-0 <3.0.0 → >=2.14.0 <3.0.0.

Flutter requirement changed in 1.0.4: >=1.17.0 → >=3.0.0.

Breaking16
Removes ProviderContainer.debugProviderValues and ProviderContainer.debugProviderElements; use ProviderContainer.getAllProviderElements instead.
ProviderContainer.debugProviderValuesProviderContainer.debugProviderElementsProviderContainer.getAllProviderElements
ProviderReference.mounted is removed; use onDispose to track disposal instead.
ProviderReference.mountedonDispose
ProviderObserver.mayHaveChanged is removed.
ProviderObserver.mayHaveChanged
ScopedProvider is removed; use Provider instead.
ScopedProviderProvider
AsyncValue.copyWith is removed.
AsyncValue.copyWith
Using ref.watch or ref.read inside a selector is no longer allowed.
ref.watchref.readselect
Removes all overrideWithProvider methods; use overrideWithValue instead.
overrideWithProvideroverrideWithValue
Renames ProviderBase.recreateShouldNotify to updateShouldNotify.
ProviderBase.recreateShouldNotifyupdateShouldNotify
Reading a StateProvider now returns its state instead of the StateController; use ref.read(someStateProvider.state) for the old behavior.
StateProviderStateControllerref.read
All providers now receive a custom subclass of ProviderRefBase as a parameter.
ProviderRefBaseProviderRefFutureProviderRefStateProviderRefProviderFutureProviderStreamProviderref.stateStateProviderref.controllerStateControllerstatecontroller
Changes the prototype of ConsumerWidget.build and Consumer.builder to receive a WidgetRef instead of ScopedReader.
ConsumerWidgetConsumerScopedReaderWidgetRefref.watch
ProviderObserver.didUpdateProvider now receives both the previous and new value.
ProviderObserver.didUpdateProvider
Family.overrideWithProvider now must create a provider.
Family.overrideWithProviderProvider.family
AsyncValue.error now takes stacktrace as a named parameter instead of positional.
AsyncValue.error
AsyncValue.when loading and error callbacks (and when variants) now receive an extra previous parameter.
AsyncValue.when
Changes Family.overrideWithProvider so it must create a provider.
Family.overrideWithProviderProvider.family
Platform1
Increases the minimum Dart SDK version to 2.14.0.
Deprecated5
Deprecates ProviderListener in favor of ref.listen.
ProviderListenerref.listen
Deprecates StreamProvider.last in favor of StreamProvider.future.
StreamProvider.lastStreamProvider.future
Deprecates ProviderReference in favor of Ref.
ProviderReferenceRef
AsyncValue.data is deprecated in favor of AsyncValue.value.
AsyncValue.dataAsyncValue.value
Deprecates ProviderReference in favor of ProviderRefBase.
ProviderReferenceProviderRefBase