listen<T> abstract method

RemoveListener listen<T>(
  1. AlwaysAliveProviderListenable<T> provider,
  2. void listener(
    1. T? previous,
    2. T next
  3. {bool fireImmediately,
  4. void onError(
    1. Object error,
    2. StackTrace stackTrace

Listen to a provider and call listener whenever its value changes.

Listeners will automatically be removed when the provider rebuilds (such as when a provider listeneed with watch changes).

Returns a function that allows cancelling the subscription early.

  • fireImmediately can be optionally passed to tell Riverpod to immediately call the listener with the current value. Defaults to false.


// TODO update ProviderContainer.listen to match the return value
RemoveListener listen<T>(
  AlwaysAliveProviderListenable<T> provider,
  void Function(T? previous, T next) listener, {
  bool fireImmediately,
  void Function(Object error, StackTrace stackTrace)? onError,