SetupWidget<T extends SetupWidget<T> > class
abstract
A widget that uses a composition-based API similar to Vue's Composition API.
The setup function executes only once when the widget is first created, not on every rebuild. This provides better performance and a more predictable execution model compared to React-style hooks.
Hot Reload Behavior
During hot reload, hooks are matched in order by their runtime type:
- If types match in sequence, existing hooks are reused and SetupHook.reassemble is called
- If a type mismatch occurs, all subsequent hooks are unmounted in reverse order
- New or replacement hooks will have SetupHook.mount called
This ensures hooks maintain correct state during development while adapting to code changes.
Example:
class CounterWidget extends SetupWidget {
const CounterWidget({super.key});
@override
setup(context, props) {
final count = useSignal(0);
return () => Column(
children: [
Text('Count: ${count.value}'),
ElevatedButton(
onPressed: () => count.value++,
child: Text('Increment'),
),
],
);
}
}
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- SetupWidget
- Implementers
Constructors
- SetupWidget({Key? key})
-
Creates a SetupWidget.
const
Properties
Methods
-
createElement(
) → SetupWidgetElement< 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
-
setup(
SetupBuildContext< T> context, PropsReadonlyNode<T> props) → SetupFunction<T> - The setup function that runs once when the widget is created.
-
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