StoreProvider<St> class
Provides a Redux Store to all ancestors of this Widget. This should generally be a root widget in your App.
Then, you have two alternatives to access the store:
- Connect to the provided store by using a StoreConnector, and the StoreConnector.vm parameter:
StoreConnector(
vm: () => Factory(this),
builder: (context, vm) => MyHomePage(user: vm.user)
);
See the documentation for more information on how to create the view-model using the vm
parameter and a VmFactory
class.
- Connect to the provided store by using a StoreConnector, and the StoreConnector.converter parameter:
StoreConnector(
converter: (Store<AppState> store) => store.state.counter,
builder: (context, value) => Text('$value', style: const TextStyle(fontSize: 30)),
);
See the documentation for more information on how to use the converter
parameter.
- Use the extension methods on BuildContext, like explained below:
You can read the state of the store using the context.state
method:
var state = context.state;
You can dispatch actions using the dispatch, dispatchAll, dispatchAndWait, dispatchAndWaitAll and dispatchSync methods:
context.dispatch(action);
context.dispatchAll([action1, action2]);
context.dispatchAndWait(action);
context.dispatchAndWaitAll([action1, action2]);
context.dispatchSync(action);
You can also use context.isWaiting
, context.isFailed()
, context.exceptionFor()
and context.clearExceptionFor()
.
IMPORTANT: You need to define this extension in your own code:
extension BuildContextExtension on BuildContext {
AppState get state => getState<AppState>();
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- ProxyWidget
- InheritedWidget
- StoreProvider
Constructors
-
StoreProvider({Key? key, required Store<
St> store, required Widget child})
Properties
- child → Widget
-
The widget below this widget in the tree.
finalinherited
- 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
-
createElement(
) → InheritedElement -
Inflates this configuration to a concrete instance.
inherited
-
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
-
updateShouldNotify(
covariant StoreProvider< St> oldWidget) → bool -
Whether the framework should notify widgets that inherit from this widget.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
backdoorInheritedWidget<
St> (BuildContext context, {Object? debug}) → Store< St> - Avoid using if you don't have a good reason to do so.
-
backdoorStaticGlobal<
St> () → Store< St> - Avoid using if you don't have a good reason to do so.
-
clearExceptionFor(
BuildContext context, Object actionOrTypeOrList, {bool notify = true}) → void -
Removes the given
actionTypeOrList
from the list of action types that failed. -
dispatch<
St> (BuildContext context, ReduxAction< St> action, {Object? debug, bool notify = true}) → FutureOr<ActionStatus> -
Dispatch an action with ReduxAction.dispatch
without needing a
StoreConnector
. Example: -
dispatchAll<
St> (BuildContext context, List< ReduxAction< actions, {Object? debug, bool notify = true}) → voidSt> > -
Dispatch a list of actions with ReduxAction.dispatchAll
without needing a
StoreConnector
. Example: -
dispatchAndWait<
St> (BuildContext context, ReduxAction< St> action, {Object? debug, bool notify = true}) → Future<ActionStatus> -
Dispatch an action with ReduxAction.dispatchAndWait
without needing a
StoreConnector
. Example: -
dispatchAndWaitAll<
St> (BuildContext context, List< ReduxAction< actions, {Object? debug, bool notify = true}) → Future<St> >void> -
Dispatch a list of actions with ReduxAction.dispatchAndWaitAll
without needing a
StoreConnector
. Example: -
dispatchSync<
St> (BuildContext context, ReduxAction< St> action, {Object? debug, bool notify = true}) → ActionStatus -
Dispatch an action with ReduxAction.dispatchSync
without needing a
StoreConnector
. Example: -
exceptionFor(
BuildContext context, Object actionOrTypeOrList, {bool notify = true}) → UserException? -
Returns the UserException of the
actionTypeOrList
that failed. -
isFailed(
BuildContext context, Object actionOrTypeOrList, {bool notify = true}) → bool -
Returns true if an
actionOrTypeOrList
failed with an UserException. -
isWaiting(
BuildContext context, Object actionOrTypeOrList, {bool notify = true}) → bool -
You can use isWaiting and pass it
actionOrActionTypeOrList
to check if: -
state<
St> (BuildContext context, {bool notify = true, Object? debug}) → St -
Get the state, without a
StoreConnector
. -
waitAllActions<
St> (BuildContext context, List< ReduxAction< actions) → Future<St> >void> -
Returns a future that completes when ALL given
actions
finished dispatching. -
waitCondition<
St> (BuildContext context, bool condition(St), {int? timeoutMillis}) → Future< ReduxAction< St> ?> -
Returns a future which will complete when the given state
condition
is true. If the condition is already true when the method is called, the future completes immediately.