watchOnly<R> method

R watchOnly<R>(
  1. BuildContext context,
  2. R selector(
    1. T value
    )
)

Watch this Observable for changes.

Whenever this Observable emits new value, if selector returns a different value, the context will be rebuilt.

Returns the selected value.

It is safe to call this method multiple times within the same build method.

Implementation

R watchOnly<R>(BuildContext context, R Function(T value) selector) {
  final observable = InheritedContextWatch.of(context)
      .getOrCreateObservable<T>(context, this);
  if (observable == null) return selector(value);

  final selectedValue = selector(value);
  observable.watchOnly(selector, selectedValue);

  return selectedValue;
}