select<TResult> method

ValueListenable<TResult> select<TResult>(
  1. TResult selector(
    1. T
    )
)

select allows you to set a filter on a ValueListenable like where, and the returned ValueListenable only emit a new value when the returned value of selector function change. With this you can react on a specific value change of a property of the ValueListenable.

example

ValueNotifier<Size> sourceListenable = ValueNotifier<Size>(const Size(10, 10));
int count = 0;
var subscription = sourceListenable.select<double>((x)=> x.height).listen((_, __) => count++);

sourceListenable.value = const Size(100,10);
sourceListenable.value = const Size(200,200);

count will be just 1

Implementation

ValueListenable<TResult> select<TResult>(TResult Function(T) selector) {
  return SelectValueNotifier(
    selector(value),
    this,
    selector,
  );
}