flutter_riverpod 1.0.0-dev.11 icon indicating copy to clipboard operation
flutter_riverpod: ^1.0.0-dev.11 copied to clipboard

A simple way to access state from anywhere in your application while robust and testable.

1.0.0-dev.11 #

Fixed an issue where dependencies did not work for ChangeNotifierProvider (#800)

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 a Future<T> That allows bypassing the loading state in the event where a value was synchronously available.

  • During loading and error states, FutureProvider and StreamProvider now expose the latest value through AsyncValue.
    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.copyWith is 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.data in favor of AsyncValue.value
  • Allowed AsyncData, AsyncError and AsyncLoading to be extended
  • Added AsyncValue.whenOrNull, similar to whenOrElse but instead of an "orElse" parameter, returns null.
  • Added AsyncValue.value, which allows reading the value without handling loading/error states.
  • AsyncError can now be instantiated with const.
  • AsyncLoading and AsyncError now optionally includes the previous state.

General #

  • Breaking All overrideWithProvider methods are removed.
    To migrate, instead use overrideWithValue.

  • 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 b if a gets 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.watch or ref.read inside 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 listened
  • fixed ref.listen now working when downcasting the value of a provider.
  • fixed a bug where disposing a scoped ProviderContainer could cause other ProviderContainers 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 ProviderObserver not working when modifying a StateProvider.
  • 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.refresh not working on some providers
  • renamed ProviderBase.recreateShouldNotify to updateShouldNotify

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: ScopedProvider is removed. To migrate, change ScopedProviders to Providers.

1.0.0-dev.1 #

  • Add missing exports (see #532)

1.0.0-dev.0 #

  • Breaking: The prototype of ConsumerWidget's build and Consumer's builder changed. Before:

    class Example extends ConsumerWidget {
      @override
      Widget build(BuildContext context, ScopedReader watch) {
        int count = watch(counterProvider);
        ...
      }
    }
    

    After:

    class Example extends ConsumerWidget {
      @override
      Widget build(BuildContext context, WidgetRef ref) {
        int count = ref.watch(counterProvider);
        ...
      }
    }
    
  • ProviderListener is deprecated. Instead, use ref.listen:

    class Example extends ConsumerWidget {
      @override
      Widget build(BuildContext context, WidgetRef ref) {
        ref.listen<int>(counter, (count) {
          print('count changed $count');
        });
      }
    }
    
  • Added ConsumerStatefulWidget + ConsumerState, a variant of StatefulWidgets that have access to a WidgetRef.

  • All "watch" functions now support myProvider.select((value) => ...). This allows filtering rebuilds:

    final userProvider = StateNotifierProvider<UserController, User>(...);
    
    Consumer(
      builder: (context, 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.overrideWithProvider now must create a provider:

    final family = Provider.family<State, Arg>(...);
    
    family.overrideWithProvider(
      (Arg arg) => Provider<State>((ref) => ...)
    );
    
  • Breaking: ProviderObserver.didUpdateProvider now receives both the previous and new value.

  • Breaking: ProviderObserver.mayHaveChanged is 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');
      });
    });
    
  • ProviderReference is deprecated in favor of ProviderRefBase.

  • All providers now receive a custom subclass of ProviderRefBase as 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, FutureProvider and StreamProvider's ref now have a state property, which represents the currently exposed value. Modifying it will notify the listeners:

      Provider<int>((ref) {
        ref.listen(onIncrementProvider, (_) {
          ref.state++;
        });
      
        return 0;
      });
      
    • StateProvider's ref now has a controller property, which allows the provider to access the StateController exposed.

  • Breaking: ProviderReference.mounted is removed. You can implement something similar using onDispose:

    Provider<T>((ref) {
      var mounted = true;
      ref.onDispose(() => mounted = false);
    });
    
  • Breaking: ProviderContainer.debugProviderValues and ProviderContainer.debugProviderElements are removed. You can now instead use ProviderContainer.getAllProviderElements.

  • StreamProvider.last, StreamProvider.stream and FutureProvider.future now expose a future/stream that is independent from how many times the associated provider "rebuilt":

    • if a StreamProvider rebuild before its stream emitted any value, StreamProvider.last will resolve with the first value of the new stream instead.
    • if a FutureProvider rebuild before its future completes, FutureProvider.future will resolve with the result of the new future instead.
  • 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 a Provider<AsyncValue<Model>>.

  • Providers can now call ref.refresh to refresh a provider, instead of having to do ref.container.refresh.

  • ref.onDispose now calls the dispose function as soon as one of the provider's dependency is known to have changed

  • Providers no longer wait until their next read to recompute their state if one of their dependency changed and they have listeners.

  • Added ProviderContainer.pump, an utility to easily "await" until providers notify their listeners or are disposed.

  • fixed an issue when using both family and autoDispose that 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+2 #

  • Fix context.refresh not compiling when using nullable providers

0.14.0+1 #

  • Re-added StateProvider.overrideWithValue/StateProvider.overrideWithProvider that were unvoluntarily removed.

0.14.0 #

  • BREAKING CHANGE The Listener/LocatorMixin typedefs are removed as the former could cause a name conflict with the widget named Listener and the latter is not supported when using Riverpod.

  • BREAKING CHANGE The syntax for using StateNotifierProvider was 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/last and FutureProvider.future.

  • feat: Calling ProviderContainer.dispose multiple time no-longer throws. This simplifies the tear-off logic of tests.

  • feat: Added ChangeNotifierProvider.notifier and StateProvider.notifier They allow obtaining the notifier associated to the provider, without causing widgets/providers to rebuild when the state updates.

  • fix: overriding a StateNotifierProvider/ChangeNotifierProvider with overrideWithValue now correctly listens to the notifier.

0.1 #

0.13.1+1 #

Fixed an issue where context.read and ProviderListener were unable to read providers that return a nullable value

0.13.1 #

0.13.0 #

  • stable null-safety release
  • ProviderObserver can now have a const constructor
  • Added the mechanism for state-inspection using the Flutter devtool
  • loosened the version constraints of freezed_annotation
  • deprecated import 'flutter_riverpod/all.dart'. Now everything is available with flutter_riverpod/flutter_riverpod.dart.
  • Fixed a but where listening to StreamProvider.last could result in a StateError (#217)
  • removed the assert preventing ConsumerWidget's "watch" from being used after the build method completed. This allows "watch" to be used inside ListView.builder.
  • context.read(myProvider) now accepts ScopeProviders

0.13.0-nullsafety.3 #

  • deprecated import 'flutter_riverpod/all.dart'. Now everything is available with flutter_riverpod/flutter_riverpod.dart.
  • removed the assert preventing ConsumerWidget's "watch" from being used after the build method completed. This allows "watch" to be used inside ListView.builder.
  • context.read(myProvider) now accepts ScopeProviders

0.13.0-nullsafety.2 #

  • Fixed outdated doc

0.13.0-nullsafety.1 #

  • Fixed a but where listening to StreamProvider.last could result in a StateError (#217)

0.13.0-nullsafety.0 #

Migrated to null-safety

0.12.2 #

  • Exported AutoDisposeProviderRefBase

0.12.1 #

0.12.0 #

0.11.2 #

0.11.1 #

  • Fixed a bug where hot-reload did not work for ConsumerWidget/Consumer

0.11.0 #

  • package:flutter_riverpod/flutter_riverpod.dart now exports StateNotifier
  • Marked the providers with @sealed so that the IDE warns against implementing/subclassing providers.
  • Fix mistakes in AsyncValue.guard's documentation (thanks @mono0926)
  • Loosened the version constraints of freezed_annotation to support 0.12.0

0.10.1 #

  • Fixed invalid version error

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:flutter_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.9.0 #

  • Breaking Updating ProviderListener so that onChange receives the BuildContext as parameter (thanks to @tbm98)

0.8.0 #

0.7.2 #

Fixed a bug that prevented the use of ConsumerWidget under normal circumstances

0.7.1 #

0.7.0 #

  • Breaking: Consumer is slightly modified to match other Builders like ValueListenableBuilder. Before:

    return Consumer((context, watch) {
      final value = watch(myProvider);
      return Text('$value');
    });
    

    after:

    return Consumer(
      builder: (context, watch, child) {
        final value = watch(myProvider);
        return Text('$value');
      },
    );
    
  • Added a ConsumerWidget class which can be extended to make a StatelessWidget that can read providers:

    class MyWidget extends ConsumerWidget {
      const MyWidget({Key? key}) : super(key: key);
    
      @override
      Widget build(BuildContext context, ScopedReader watch) {
        final value = watch(myProvider);
        return Text('$value');
      }
    }
    
  • ref.watch on 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

  • ScopedProvider now accepts null as a function:

    final example = ScopedProvider<int>(null);
    

    Which is equivalent to:

    final example = ScopedProvider<int>((watch) => throw UnimplementedError(''));
    
  • Fixed a bug where context.refresh may not work properly if the widget tree contains multiple ProviderScope.

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 Computed and Provider. 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 (now Provider) 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 ProviderStateOwner to ProviderContainer

  • Renamed ProviderStateOwnerObserver to ProviderObserver

  • It is no-longer possible to override a provider anywhere in the widget tree. Providers can only be overridden in the top-most ProviderScope/ProviderContainer.

  • Providers can now read values which may change over time using ref.read and ref.watch. When using ref.watch, if the value obtained changes, this will cause the provider to re-create its state.

  • It is no-longer possible to add ProviderObserver anywhere in the widget tree. They can be added only on the top-most ProviderScope/ProviderContainer.

  • Provider.read(BuildContext) is changed into context.read(provider), and can now read Provider.autoDispose.

  • Added ProviderContainer.refresh(provider) and context.refresh(provider). These 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 a Stream<T> but an AsyncValue<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 a Future<T> but an AsyncValue<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 use ref.read/ref.watch to acheive 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 into ProviderContainer.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.autoDispose now correctly free both the arguments and the associated providers from memory when the provider is no-longer listened.

  • Added ScopedProvider, a new kind of provider that can be overridden anywhere in the widget tree. Normal providers cannot read a ScopedProvider.

  • Added ProviderListener, a widget which allows listening to a provider without rebuilding the widget-tree. This can be useful for showing modals and pushing routes.

0.5.1 #

  • Fixed the documentation of StateNotifierProvider incorrectly showing the documentation of StreamProvider.
  • Improve the documentation of StateProvider.

0.5.0 #

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 for AsyncValue.when to handle only the data case and do nothing for the error/loading cases.

  • Fixed a bug that caused [Computed] to crash if it stopped being listened then was listened again.

0.2.1 #

  • Computed and Consumer now correctly unsubscribe to a provider when their function stops using a provider.

0.2.0 #

  • ref.read is renamed as ref.dependOn
  • Deprecated ref.dependOn(streamProvider).stream and ref.dependOn(futureProvider).future in favor of a universal ref.dependOn(provider).value.
  • added ref.read(provider), syntax sugar for ref.dependOn(provider).value.

0.1.0 #

Initial release

730
likes
130
pub points
99%
popularity

Publisher

shield icon for verified publishersdash-overflow.net

A simple way to access state from anywhere in your application while robust and testable.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

collection, flutter, meta, riverpod, state_notifier

More

Packages that depend on flutter_riverpod