LogoSignals.dart
Copy Markdown
rodydavis/signals.dart 999999

Type: SignalStatefulWidget

API reference and details for SignalStatefulWidget from signals.dart.

SignalStatefulWidget#

Kind: 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: