dispatchAndWait property

DispatchAndWait<St> dispatchAndWait

Dispatches the action, applying its reducer, and possibly changing the store state. The action may be sync or async. In both cases, it returns a Future that resolves when the action finishes.

await store.dispatchAndWait(DoThisFirstAction());
store.dispatch(DoThisSecondAction());

If you pass the notify parameter as false, widgets will not necessarily rebuild because of this action, even if it changes the state.

Note: While the state change from the action's reducer will have been applied when the Future resolves, other independent processes that the action may have started may still be in progress.

Method dispatchAndWait is of type DispatchAndWait. It returns Future<ActionStatus>, which means you can also get the final status of the action after you await it:

var status = await store.dispatchAndWait(MyAction());

See also:

  • dispatch which dispatches both sync and async actions.
  • dispatchAll which dispatches all given actions in parallel.
  • dispatchAndWaitAll which dispatches all given actions, and returns a Future.
  • dispatchSync which dispatches sync actions, and throws if the action is async.

Implementation

DispatchAndWait<St> get dispatchAndWait => _store.dispatchAndWait;