listenManual<T> abstract method

ProviderSubscription<T> listenManual<T>(
  1. ProviderListenable<T> provider,
  2. void listener(
    1. T? previous,
    2. T next
    ), {
  3. void onError(
    1. Object error,
    2. StackTrace stackTrace
    )?,
  4. bool fireImmediately,
})

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

As opposed to listen, listenManual is not safe to use within the build method of a widget. Instead, listenManual is designed to be used inside State.initState or other State lifecycles.

listenManual returns a ProviderSubscription which can be used to stop listening to the provider, or to read the current value exposed by the provider.

It is not necessary to call ProviderSubscription.close inside State.dispose. When the widget that calls listenManual is disposed, the subscription will be disposed automatically.

Implementation

ProviderSubscription<T> listenManual<T>(
  ProviderListenable<T> provider,
  void Function(T? previous, T next) listener, {
  void Function(Object error, StackTrace stackTrace)? onError,
  bool fireImmediately,
});