Selector< A, S> class
An equivalent to Consumer that can filter updates by selecting a limited amount of values and prevent rebuild if they don't change.
Selector will obtain a value using Provider.of, then pass that value
to selector
. That selector
callback is then tasked to return an object
that contains only the information needed for builder
to complete.
By default, Selector determines if builder
needs to be called again
by comparing the previous and new result of selector
using
DeepCollectionEquality
from the package collection
.
This behavior can be overridden by passing a custom shouldRebuild
callback.
NOTE:
The selected value must be immutable, or otherwise Selector may think
nothing changed and not call builder
again.
As such, it selector
should return either a collection (List/Map/Set/Iterable)
or a class that override ==
.
To select multiple values without having to write a class that implements ==
,
the easiest solution is to use a "Tuple" from tuple:
Selector<Foo, Tuple2<Bar, Baz>>(
selector: (_, foo) => Tuple2(foo.bar, foo.baz),
builder: (_, data, __) sync* {
yield Text('${data.item1} ${data.item2}');
}
)
In that example, builder
will be called again only if foo.bar
or
foo.baz
changes.
For generic usage information, see Consumer.
- Inheritance
-
- Object
- SingleChildStatefulComponent
- Selector0<
S> - Selector
Constructors
-
Selector({Key? key, required ValueComponentBuilder<
S> builder, required S selector(BuildContext, A), ShouldRebuild< S>? shouldRebuild, Component? child}) - An equivalent to Consumer that can filter updates by selecting a limited amount of values and prevent rebuild if they don't change.
Properties
-
builder
→ ValueComponentBuilder<
S> -
A function that builds a component tree from
child
and the last result of selector.finalinherited - hashCode → int
-
The hash code for this object.
read-onlyinherited
- key → Key?
-
Controls how one component replaces another component in the tree.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
read-onlyinherited
- selector → S Function(BuildContext)
-
A function that obtains some
InheritedComponent
and map their content into a new object with only a limited number of properties.finalinherited
Methods
-
createElement(
) → SingleChildStatefulElement -
Creates a
StatefulElement
to manage this component's location in the tree.inherited -
createState(
) → _Selector0State< S> -
Creates the mutable state for this component at a given location in the tree.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited