select<T, R> method
R
select<T, R>(
- R selector(
- T value
What selector picks from the T of the nearest provider of one
above this context, which is rebuilt only when a change of the value
makes selector pick something else: not ==, lists, sets, maps and
other iterables compared element by element. A build may select any
number of parts, of one value or of several; each build selects anew.
A ProviderNotFoundException if there is none, unless T is
nullable.
selector picks with the value alone: reading, watching or selecting
another provider in it is an error while asserts are on.
Implementation
R select<T, R>(R Function(T value) selector) {
final scope = _scopeOf<T>(this);
final type = widget.runtimeType;
final value = scope?.value;
if (value is! T) {
throw ProviderNullException(T, type);
}
final selected = _selecting(() => selector(value));
if (scope != null) {
dependOnInheritedElement(scope);
scope._dependOnPart(this, (current) {
if (current is! T) {
throw ProviderNullException(T, type);
}
return !deepEquals(selector(current), selected);
});
}
return selected;
}