setup abstract method
The setup function that runs once when the widget is created.
This function should return a WidgetFunction that will be called on each rebuild. Use hooks like useSignal, useComputed, etc. to manage reactive state within this function.
Hooks are cached and reused across hot reloads based on their runtime type and position in the sequence. If the hook sequence changes during hot reload, mismatched hooks will be unmounted and recreated.
Parameters
- context: The standard Flutter BuildContext for accessing inherited widgets
- props: A PropsReadonlyNode that provides reactive access to widget properties
Returns
A WidgetFunction that builds the widget tree. This builder runs on each reactive rebuild when tracked dependencies change.
Example
@override
setup(context, props) {
// Access reactive props
final title = useComputed(() => props().title);
// Create local reactive state
final count = useSignal(0);
// Return builder function
return () => Column(
children: [
Text(title.value),
Text('Count: ${count.value}'),
],
);
}
Implementation
WidgetFunction<T> setup(BuildContext context, PropsReadonlyNode<T> props);