listenSelf method

  1. @override
void listenSelf(
  1. void listener(
    1. StateT? previous,
    2. StateT next
    ), {
  2. void onError(
    1. Object error,
    2. StackTrace stackTrace
    )?,
})
override

Listens to changes on the value exposed by this provider.

The listener will be called immediately after the provider completes building.

As opposed to listen, the listener will be called even if ProviderElementBase.updateShouldNotify returns false, meaning that the previous and new value can potentially be identical.

Implementation

@override
void listenSelf(
  void Function(StateT? previous, StateT next) listener, {
  void Function(Object error, StackTrace stackTrace)? onError,
}) {
  // TODO do we want to expose a way to close the subscription?
  // TODO do we want a fireImmediately?

  _onChangeSelfListeners ??= [];
  _onChangeSelfListeners!.add(listener);

  if (onError != null) {
    _onErrorSelfListeners ??= [];
    _onErrorSelfListeners!.add(onError);
  }
}