select<TResult> method Null safety

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.

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,
  );
}