watchComputed<T> method

Widget watchComputed<T>(
  1. T compute(),
  2. Widget builder(
    1. T value
    )
)

Watch a computed value

Implementation

Widget watchComputed<T>(
  T Function() compute,
  Widget Function(T value) builder,
) {
  T cachedValue = compute();
  return ReactiveBuilder<ReactiveModel>(
    model: this,
    builder: (_) {
      final newValue = compute();
      if (cachedValue != newValue) cachedValue = newValue;
      return builder(cachedValue);
    },
  );
}