SetupMixin<T extends StatefulWidget> mixin
A mixin that brings setup-based composition API to StatefulWidget.
This mixin allows you to use Jolt's reactive setup pattern with traditional StatefulWidget, providing a bridge between Flutter's standard widget system and Jolt's composition API.
Usage
class MyWidget extends StatefulWidget {
final String title;
final int initialCount;
const MyWidget({super.key, required this.title, required this.initialCount});
@override
State<MyWidget> createState() => _MyWidgetState();
}
class _MyWidgetState extends State<MyWidget> with SetupMixin<MyWidget> {
@override
setup(context) {
// Access widget properties via props getter
final count = useSignal(props.initialCount);
// Use any Jolt hooks
useEffect(() {
print('Title: ${props.title}');
}, [props.title]);
return () => Column(
children: [
Text(props.title),
Text('Count: ${count.value}'),
ElevatedButton(
onPressed: () => count.value++,
child: Text('Increment'),
),
],
);
}
}
Features
- Props Access: Use the props getter to access widget properties reactively
- Hooks Support: All Jolt hooks (useSignal, useComputed, useEffect, etc.)
- Lifecycle Integration: Automatically integrates with Flutter's State lifecycle
- Hot Reload: Full hot reload support with hook state preservation
Lifecycle
The mixin automatically handles:
- Setup function runs on first build (after initState, before first build)
- Props updates trigger JoltSetupContext.notifyUpdate
- Dependencies changes trigger JoltSetupContext.notifyDependenciesChanged
- Cleanup on dispose
When to Use
Use SetupMixin when:
- You need StatefulWidget features (like State.mounted)
- Integrating with existing StatefulWidget code
- You prefer State's lifecycle methods
Use SetupWidget when:
- Building new components from scratch
- You want the simplest API
- Element's lifecycle is sufficient
- Superclass constraints
- State<
T>
- State<
Properties
- context → BuildContext
-
The location in the tree where this widget builds.
no setterinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- mounted → bool
-
Whether this State object is currently in a tree.
no setterinherited
- props → T
-
Provides direct access to the widget properties.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
setupContext
→ JoltSetupContext<
T> -
latefinal
- widget → T
-
The current configuration.
no setterinherited
Methods
-
activate(
) → void -
Called when this object is reinserted into the tree after having been
removed via deactivate.
override
-
build(
BuildContext context) → Widget -
Describes the part of the user interface represented by this widget.
override
-
deactivate(
) → void -
Called when this object is removed from the tree.
override
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
didChangeDependencies(
) → void -
Called when a dependency of this State object changes.
override
-
didUpdateWidget(
covariant T oldWidget) → void -
Called whenever the widget configuration changes.
override
-
dispose(
) → void -
Called when this object is removed from the tree permanently.
override
-
initState(
) → void -
Called when this object is inserted into the tree.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
reassemble(
) → void -
Called whenever the application is reassembled during debugging, for
example during hot reload.
override
-
setState(
VoidCallback fn) → void -
Notify the framework that the internal state of this object has changed.
inherited
-
setup(
BuildContext context) → WidgetFunction< 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
-
toStringShort(
) → String -
A brief description of this object, usually just the runtimeType and the
hashCode.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited