SetupBuilder class
A convenience widget that uses a builder function for setup.
SetupBuilder provides the simplest way to use Jolt's setup API without creating a custom widget class. It's ideal for quick prototyping, simple components, or inline reactive widgets.
When to Use
Use SetupBuilder when:
- Prototyping or experimenting with reactive state
- Creating simple, self-contained components
- You don't need custom widget properties
- The component logic is straightforward
Use SetupWidget subclass when:
- You need custom properties (title, count, callback, etc.)
- Building reusable components with clear APIs
- The component is complex or will be used in multiple places
- You want better IDE support and type checking for properties
Example
// Simple counter - no custom properties needed
SetupBuilder(
setup: (context) {
final count = useSignal(0);
useEffect(() {
print('Count changed: ${count.value}');
}, [count.value]);
return () => Column(
children: [
Text('Count: ${count.value}'),
ElevatedButton(
onPressed: () => count.value++,
child: const Text('Increment'),
),
],
);
},
)
Comparison with SetupWidget
// SetupBuilder: For simple widgets without custom properties
SetupBuilder(
setup: (context) {
final count = useSignal(0);
return () => Text('Count: ${count.value}');
},
)
// SetupWidget: For reusable widgets with custom properties
class Counter extends SetupWidget<Counter> {
final int initialValue;
final String label;
const Counter({
super.key,
required this.initialValue,
required this.label,
});
@override
setup(context, props) {
// Access reactive props through props parameter
final count = useSignal(props().initialValue);
// React to prop changes
final displayText = useComputed(() =>
'${props().label}: ${count.value}'
);
return () => Text(displayText.value);
}
}
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- SetupWidget<
SetupBuilder> - SetupBuilder
Constructors
-
SetupBuilder({Key? key, required WidgetFunction<
SetupBuilder> setup(BuildContext)}) -
Creates a SetupBuilder.
const
Properties
Methods
-
createElement(
) → SetupWidgetElement< SetupBuilder> -
Inflates this configuration to a concrete instance.
inherited
-
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
-
setup(
BuildContext context, PropsReadonlyNode< SetupBuilder> props) → WidgetFunction<SetupBuilder> -
The setup function that runs once when the widget is created.
override
-
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