addListener method
ProviderSubscription<StateT>
addListener(
- Node node,
- void listener(
- StateT? previous,
- StateT next
- required void onError(
- Object error,
- StackTrace stackTrace
- required void onDependencyMayHaveChanged()?,
- required bool fireImmediately,
override
Starts listening to this transformer
Implementation
@override
ProviderSubscription<StateT> addListener(
Node node,
void Function(StateT? previous, StateT next) listener, {
required void Function(Object error, StackTrace stackTrace)? onError,
required void Function()? onDependencyMayHaveChanged,
required bool fireImmediately,
}) {
onError ??= Zone.current.handleUncaughtError;
final element = node.readProviderElement(this);
element.flush();
if (fireImmediately) {
handleFireImmediately(
element.getState()!,
listener: listener,
onError: onError,
);
}
// Calling before initializing the subscription,
// to ensure that "hasListeners" represents the state _before_
// the listener is added
element._onListen();
return _ProviderStateSubscription<StateT>(
node,
listenedElement: element,
listener: (prev, next) => listener(prev as StateT?, next as StateT),
onError: onError,
);
}