signal<T> function

FlutterSignal<T> signal<T>(
  1. T value, {
  2. SignalOptions<T>? options,
  3. @Deprecated('Use options: SignalOptions(name: ...) instead') String? debugLabel,
  4. @Deprecated('Use options: SignalOptions(autoDispose: ...) instead') bool? autoDispose,
  5. bool runCallbackOnListen = false,
})

Creates a mutable, reactive FlutterSignal initialized with the given value.

When the value changes, all registered builders, effects, and ValueNotifier listeners are automatically scheduled to update/rebuild.

Flutter Widget Example

final count = signal(0);

class CounterView extends StatelessWidget {
  const CounterView({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: SignalBuilder(
          builder: (context) => Text('Count: ${count.value}'),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () => count.value++,
        child: const Icon(Icons.add),
      ),
    );
  }
}

Implementation

FlutterSignal<T> signal<T>(
  T value, {
  core.SignalOptions<T>? options,
  @Deprecated('Use options: SignalOptions(name: ...) instead')
  String? debugLabel,
  @Deprecated('Use options: SignalOptions(autoDispose: ...) instead')
  bool? autoDispose,
  bool runCallbackOnListen = false,
}) {
  return FlutterSignal<T>(
    value,
    options: options,
    debugLabel: debugLabel,
    autoDispose: autoDispose,
    runCallbackOnListen: runCallbackOnListen,
  );
}