ReactterSelector
The ReactterSelector
widget is an similarly to ReactterConsumer
. It obtains the dependency provided by the closest ReactterProvider
widget and allows you to select a specific value from the state to rebuild the widget tree when the value changes.
Syntax
Properties
key
: An optionalKey
to use for identifying the widget.id
: An optionalString
to identify the selector.child
: An optionalWidget
which is independent of theReactterSelector
. If defined, it is passed to thebuilder
function.-
selector
: A function that computes a valueV
from one or more states and listens for changes to rebuild the widget tree when the value changes. It receives the following arguments:instance
: The instance ofT
dependency provided by the closestReactterProvider
widget.select
: A function that allows you to wrap the state to be listened for changes and returns it.
-
builder
: A function that builds a widget depending on theReactterSelector
. It receives the following arguments:context
: TheBuildContext
of the widget. A handle to the location ofReactterSelector
in the widget tree.instance
: The instance ofT
dependency provided by the closestReactterProvider
widget.value
: The selected value computedV
by theselector
function.child
: Thechild
widget passed to theReactterSelector
widget.
Usage
Basic Usage
In the following example, we have a simple counter application that uses the ReactterSelector
widget to select a specific value from the state to rebuild the widget tree when the value changes.