watchEffect method

void watchEffect(
  1. BuildContext context,
  2. void effect(
    1. T1,
    2. TListenable2
    ), {
  3. Object? key,
  4. bool immediate = false,
  5. 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, TListenable2) effect, {
  Object? key,
  bool immediate = false,
  bool once = false,
}) {
  return watchEffect2<T1, TListenable2, T1, TListenable2>(context, effect, $1, $2, ContextWatcherObservableType.valueListenable, ContextWatcherObservableType.listenable, key: key, immediate: immediate, once: once);
}