SignalProvider#
class |
Package: package:signals_flutter
Class: SignalProvider#
A premium dependency-injection / state propagation widget that allows passing reactive signals down the Flutter widget tree using InheritedNotifier.
SignalProvider makes a signal accessible to all child widgets in the subtree.
Any child widget that reads the signal using SignalProvider.of
will
automatically rebuild when the signal's value changes, while parent widgets remain unaffected.
For version 7, SignalProvider is a stateful widget that manages the lifecycle of the created
signal, ensuring it is persisted across parent rebuilds and automatically calling
dispose()
when the provider is unmounted to prevent memory leaks.
Example Usage#
1. Standard Constructor (Manages Lifecycle)
SignalProvider<CounterSignal>(
create: () => CounterSignal(0),
child: const CounterDisplay(),
)
2. Value Constructor (Exposes Existing Instance)
If the signal is created elsewhere (e.g. in a StatefulWidget's State or globally) and you want to expose it without managing its lifecycle or calling dispose, use SignalProvider.value:
SignalProvider<CounterSignal>.value(
value: myCounterSignal,
child: const CounterDisplay(),
)
3. Multi-Providing Multiple Signals
Wrap multiple providers in a flat list to avoid deeply nested trees using SignalProvider.multi:
SignalProvider.multi(
providers: [
SignalProvider<Counter>(create: () => Counter()),
SignalProvider<User>(create: () => User()),
],
child: const MyApp(),
)
Members of SignalProvider#
| Member | Type | Signature | Description |
|---|---|---|---|
| SignalProvider | constructor |
dart SignalProvider({super.key, required T Function() create, this.child, this.dispose})
|
Creates a SignalProvider that manages the lifecycle of a created signal. |
| SignalProvider.value | constructor |
dart SignalProvider.value({super.key, required T value, this.child}) |
Exposes an existing signal value to the widget tree. |
| SignalProvider._ | constructor |
dart SignalProvider._({super.key, required T Function()? create, required T? value, required this.child, required this.dispose})
|
Private constructor for internal cloning and subclass usage. |
| child | field |
dart Widget? child |
The widget subtree that will have access to the signal. |
| dispose | field |
dart void Function(T)? dispose |
An optional custom dispose callback. |
| SignalProvider.multi | constructor |
dart SignalProvider.multi({Key? key, required List
|
Creates a SignalProvider that wraps multiple other SignalProvider s. |
| copyWith | method |
dart SignalProvider |
Returns a clone of this SignalProvider with a new child widget. |
| createState | method |
dart State<SignalProvider |
|
| providerOf | method |
dart static SignalProvider
|
Retrieves the SignalProvider widget itself from the ancestor path. |
| of | method |
dart static T? of(BuildContext context, {bool listen = true}) |
Retrieves the reactive signal instance of type T directly from the nearest SignalProvider . |
References#
The SignalProvider type is referenced and used in the following pages:
- Dependency Injection (guides)
- signals_flutter
- MultiSignalProvider (signals_flutter/widgets)
- SignalProvider (signals_flutter/widgets)
- signals
- MultiSignalProvider (signals/widgets)
- SignalProvider (signals/widgets)
- useSignalProvider (signals_hooks/hooks)