watchEffect method
void
watchEffect(
- BuildContext context,
- void effect(
- TListenable0,
- AsyncSnapshot<
T1> , - AsyncSnapshot<
T2> , - TListenable3,
- Object? key,
- bool immediate = false,
- bool once = false,
Watch all observables for changes.
Whenever any observable notifies of a change, the effect
will be
called with the latest values of all observables, without rebuilding the widget.
Conditional effects are supported, but it's highly recommended to specify
a unique key
for all such effects followed by the unwatchEffect call
when condition is no longer met:
if (condition) {
(listenable, stream, future).watchEffect(context, key: 'effect', (_, _, _) {...});
} else {
(listenable, stream, future).unwatchEffect(context, key: 'effect');
}
If immediate
is true
, the effect will be called upon effect
registration immediately. If once
is true
, the effect will be called
only once. These parameters can be combined.
immediate
and once
parameters require a unique key
.
Implementation
void watchEffect(
BuildContext context,
void Function(TListenable0, AsyncSnapshot<T1>, AsyncSnapshot<T2>, TListenable3) effect, {
Object? key,
bool immediate = false,
bool once = false,
}) {
return watchEffect4<TListenable0, AsyncSnapshot<T1>, AsyncSnapshot<T2>, TListenable3, TListenable0, T1, T2, TListenable3>(context, effect, $1.of(context), $2.of(context), $3.of(context), $4.of(context), ContextWatcherObservableType.listenable, ContextWatcherObservableType.stream, ContextWatcherObservableType.stream, ContextWatcherObservableType.listenable, key: key, immediate: immediate, once: once);
}