listen<State> method
ProviderSubscription<State>
listen<State>(
- ProviderListenable<
State> provider, - void listener(
- State? previous,
- State next
- bool fireImmediately = false,
- void onError(
- Object error,
- StackTrace stackTrace
Subscribe to this provider.
See also:
- ProviderSubscription, which allows reading the current value and closing the subscription.
- Ref.watch, which is an easier way for providers to listen to another provider.
Implementation
ProviderSubscription<State> listen<State>(
ProviderListenable<State> provider,
void Function(State? previous, State next) listener, {
bool fireImmediately = false,
void Function(Object error, StackTrace stackTrace)? onError,
}) {
// TODO test always flushed provider
if (provider is _ProviderSelector<Object?, State>) {
return provider.listen(
this,
listener,
fireImmediately: fireImmediately,
onError: onError,
);
}
final element = readProviderElement(provider as ProviderBase<State>);
return element.addListener(
provider,
listener,
fireImmediately: fireImmediately,
onError: onError,
);
}