autorunWithLocator method
ReactionDisposer
autorunWithLocator(
- LocatorAutorunFn fn,
- {String? name,
- int? delay,
- ReactiveContext? context,
- OnError? onError}
Executes the specified fn
, whenever the dependent observables change.
Also executes fn
when the observable locator scope changes.
The reaction will be disposed automatically when the widget state is disposed.
Returns a disposer that can be used to dispose the autorun early.
This function can safely be called in initState. If called in a method that is run multiple times such as didUpdateWidget, it is the responsibility of the caller to dispose of older stale reactions.
Implementation
ReactionDisposer autorunWithLocator(
LocatorAutorunFn fn, {
String? name,
int? delay,
ReactiveContext? context,
OnError? onError,
}) {
final reaction = _AutorunDef(fn, name, delay, context, onError, (reaction) {
_reactions.remove(reaction);
});
_addReaction(reaction);
return reaction.dispose;
}