JoltSelector<T> class
A widget that rebuilds only when a specific selector function's result changes.
JoltSelector provides fine-grained control over when rebuilds occur by watching a selector function. The widget only rebuilds when the selector's return value changes, making it more efficient than JoltBuilder for scenarios where you only need to react to specific derived values.
The selector function receives the previous selected value (or null on first run)
and returns the new value to watch. Rebuilds occur only when the returned value
changes (using equality comparison).
When to Use
Use JoltSelector when you need to:
- Select a specific value from a complex object
- Filter or transform reactive data before rebuilding
- Avoid unnecessary rebuilds when unrelated parts of a signal change
For general reactive UI needs, JoltBuilder is simpler and recommended.
Parameters
- builder: Function that builds the widget tree. Receives the context and the current selected value.
- selector: Function that computes the value to watch for changes. Receives
the previous selected value (or
nullon first run) and returns the new value.
Example
final user = Signal(User(name: 'John', age: 30));
// Only rebuilds when the user's name changes, not age
JoltSelector(
selector: (prev) => user.value.name,
builder: (context, name) => Text('Hello $name'),
)
With multiple signals:
final firstName = Signal('John');
final lastName = Signal('Doe');
JoltSelector(
selector: (prev) => '${firstName.value} ${lastName.value}',
builder: (context, fullName) => Text('Hello $fullName'),
)
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- JoltSelector
Constructors
- JoltSelector({Key? key, required Widget builder(BuildContext context, T state), required T selector(T? prevState)})
-
const
Properties
- builder → Widget Function(BuildContext context, T state)
-
Function that builds the widget tree.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- selector → T Function(T? prevState)
-
Function that computes the value to watch for changes.
final
Methods
-
createElement(
) → JoltSelectorElement< T> -
Inflates this configuration to a concrete instance.
override
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited