SystemProviders<S, E> class
SystemProviders
can consume a System
then provide state
and dispatch
to descendant widgets.
SystemProviders
will break the System
into smaller units (state
, dispatch
etc.),
and provide these units to descendant.
Configurations:
SystemProviders(
create: (context) => createSystem(), // A factory to create system, required.
provideState: true, // Whether to provide `State`, default `true`.
provideStates: false, // Whether to provide `Stream<State>`, default `false`.
provideDispatch: true, // Whether to provide `Dispatch<E>`, default `true`.
stateEquals: (it1, it2) => it1 == it2, // Whether new `state` are equal to old `state`.
// New state will be emitted only if it's not equal to old state.
// defaults to `==`.
builder: (context, child) => ..., // widget builder, nullable.
child: SomeWidget(), // child widget, nullable.
);
Descendant widget can access state
and dispatch
from context
:
System<int, CounterEvent> createCounterSystem() { ... }
class UseSystemProvidersPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return SystemProviders(
create: (_) => createCounterSystem(),
builder: (context, _) {
final state = context.watch<int>(); // <- access state
return CounterPage(
title: 'Use System Providers Page',
count: state,
onIncreasePressed: () => context.dispatch<CounterEvent>(Increment()), // <- access dispatch
);
},
);
}
}
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- SingleChildStatefulWidget
- SystemProviders
Constructors
-
SystemProviders({Key? key, required Create<
System< create, bool provideState = true, bool provideStates = false, bool provideDispatch = true, Equals<S, E> >S> ? stateEquals, TransitionBuilder? builder, Widget? child}) -
const
-
SystemProviders.value({Key? key, required System<
S, E> value, bool provideState = true, bool provideStates = false, bool provideDispatch = true, Equals<S> ? stateEquals, TransitionBuilder? builder, Widget? child})
Properties
- builder → TransitionBuilder?
-
final
-
create
→ Create<
System< S, E> > -
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- provideDispatch → bool
-
final
- provideState → bool
-
final
- provideStates → bool
-
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
stateEquals
→ Equals<
S> ? -
final
Methods
-
createElement(
) → SingleChildStatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< StatefulWidget> -
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
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) → 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