onBlocState method

Future<SilentActionResult> onBlocState(
  1. NodeSpec action,
  2. ActionContext context
)

Implementation

Future<SilentActionResult> onBlocState(
    NodeSpec action, ActionContext context) async {
  final stateName = action.props["name"] as String?;
  if (stateName == null || stateName.isEmpty) {
    return SilentActionResult(true);
  }

  final state = ActionState(action.props["name"], action.props["data"]);
  if (action.props["type"] == "global") {
    GlobalBloc.emitState(state);
  } else {
    try {
      BlocProvider.of<LocalBloc>(context.buildContext).add(EmitState(state));
    } catch (e, stack) {
      log.severe("LocalBloc not found while emitting BlocState.", e, stack);
    }
  }
  return SilentActionResult(true);
}