BuildContext.select
Esta página aún no está disponible en tu idioma.
BuildContext.select
is a method that computes a value whenever the selected states change and registers the current widget as a listener for these changes.
Consequently, each time the selected states change, the value is recalculated and if it is different from the previous one, the widget is automatically notified and rebuilt.
Syntax & description
context
: TheBuildContext
object, which provides information about the current widget in the tree.-
T
: The type of the dependency you want to select. It is used to locate the dependency from the nearest ancestor provider. -
V
: The type of the value you want to compute. It is the return type of thecomputeValue
function. -
computeValue
: A function that computes the value based on the selected states. It takes two arguments:instance
: The instance of the dependency of typeT
.-
select
: A function that allows you to wrap the state(RtState
) to be listened for changes and returns it.
id
: An optional identifier for theT
dependency. If omitted, the dependency will be located by its type (T
).
Usage
This following example demonstrates how to use BuildContext.select
:
In this example, checks if the count
state from CounterController
is divisible by a specified number (byNum
).
The BuildContext.select
method is used to perform this check and rebuild the widget tree whenever the divisibility status changes.