SignalStatefulWidget#
class |
Package: package:signals_flutter
Class: SignalStatefulWidget#
A reactive StatefulWidget that implicitly tracks and rebuilds on signal changes.
Subclasses of SignalStatefulWidget establish a dynamic reactive context directly at the
Flutter element layer. Any signal value accessed synchronously inside State's build
method
is implicitly tracked and subscribed to. When a signal changes, only that element is rebuilt.
This offers a clean, Javascript-style reactivity experience while retaining all stateful lifecycles.
It is the modern, highly recommended replacement for the legacy, deprecated SignalsMixin.
Implicit Reactivity Example (Stateful)#
class CounterControl extends SignalStatefulWidget {
const CounterControl({super.key});
@override
State<CounterControl> createState() => _CounterControlState();
}
class _CounterControlState extends State<CounterControl> {
// Create state signals directly inside the State object:
final count = signal(0);
@override
Widget build(BuildContext context) {
// Automatically tracked on access and safely unsubscribed on unmount:
return ElevatedButton(
onPressed: () => count.value++,
child: Text('Count: ${count.value}'),
);
}
}
Important
Only signals accessed synchronously during the execution of the build method are tracked.
Signals read inside async callbacks, listeners, or deferred tasks are not subscribed to.
Members of SignalStatefulWidget#
| Member | Type | Signature | Description |
|---|---|---|---|
| SignalStatefulWidget | constructor |
dart SignalStatefulWidget({super.key}) |
Constructor for SignalStatefulWidget. |
| createElement | method |
dart StatefulElement createElement() |
References#
The SignalStatefulWidget type is referenced and used in the following pages:
- SignalsMixin (signals_flutter/mixins)
- SignalStatefulElement (signals_flutter/extensions)
- Stateful Widget Convert Widget Extension (signals_flutter/extensions)
- ConvertedSignalStatefulWidget (signals_flutter/extensions)
- SignalStatefulWidget (signals_flutter/extensions)
- signals_flutter
- SignalsAvoidDeprecatedWatchExtension (signals_lint/flutter)
- ConvertStatefulToSignalStatefulWidget (signals_lint/flutter)
- SignalsAvoidDeprecatedSignalsMixin (signals_lint/flutter)
- MigrateSignalsMixinToSignalStatefulWidget (signals_lint/flutter)
- SignalsMixin (signals/mixins)
- SignalStatefulElement (signals/extensions)
- Stateful Widget Convert Widget Extension (signals/extensions)
- ConvertedSignalStatefulWidget (signals/extensions)
- SignalStatefulWidget (signals/extensions)
- signals