watchEffect method
void
watchEffect(
- BuildContext context,
- void effect(
- AsyncSnapshot<
T0> , - TListenable1,
- AsyncSnapshot<
T2>
- AsyncSnapshot<
- 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(AsyncSnapshot<T0>, TListenable1, AsyncSnapshot<T2>) effect, {
Object? key,
bool immediate = false,
bool once = false,
}) {
return watchEffect3<AsyncSnapshot<T0>, TListenable1, AsyncSnapshot<T2>, T0, TListenable1, T2>(context, effect, $1.of(context), $2.of(context), $3.of(context), ContextWatcherObservableType.stream, ContextWatcherObservableType.listenable, ContextWatcherObservableType.stream, key: key, immediate: immediate, once: once);
}