watchEffect method
void
watchEffect(
- BuildContext context,
- void effect(
- T1,
- T3,
- AsyncSnapshot<
T4>
- 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(T1, T3, AsyncSnapshot<T4>) effect, {
Object? key,
bool immediate = false,
bool once = false,
}) {
return watchEffect3<T1, T3, AsyncSnapshot<T4>, T1, T3, T4>(context, effect, $1.of(context), $2.of(context), $3.of(context), ContextWatcherObservableType.valueListenable, ContextWatcherObservableType.valueListenable, ContextWatcherObservableType.future, key: key, immediate: immediate, once: once);
}