SignalProvider<T extends FlutterReadonlySignal> class
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<T>(context) 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(),
)
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- SignalProvider
- Available extensions
Constructors
- SignalProvider({Key? key, required T create(), Widget? child, void dispose(T)?})
-
Creates a SignalProvider that manages the lifecycle of a created signal.
const
-
SignalProvider.multi({Key? key, required List<
SignalProvider< providers, required Widget child})FlutterReadonlySignal> > -
Creates a SignalProvider that wraps multiple other SignalProviders.
constfactory
- SignalProvider.value({Key? key, required T value, Widget? child})
-
Exposes an existing signal
valueto the widget tree.const
Properties
- child → Widget?
-
The widget subtree that will have access to the signal.
final
- dispose → void Function(T)?
-
An optional custom dispose callback.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
copyWith(
Widget child) → SignalProvider< T> -
Returns a clone of this SignalProvider with a new
childwidget. Used internally by MultiSignalProvider. -
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< SignalProvider< T> > -
Creates the mutable state for this widget at a given location in the tree.
override
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toSignalStatefulWidget(
) → SignalStatefulWidget -
Available on StatefulWidget, provided by the StatefulWidgetConvertWidgetExtension extension
Converts this StatefulWidget to a SignalStatefulWidget. -
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
of<
T extends FlutterReadonlySignal> (BuildContext context, {bool listen = true}) → T? -
Retrieves the reactive signal instance of type
Tdirectly from the nearest SignalProvider. -
providerOf<
T extends FlutterReadonlySignal> (BuildContext context, {bool listen = true}) → SignalProvider< T> ? - Retrieves the SignalProvider widget itself from the ancestor path.