postExecute method

  1. @protected
Future<NodeSpec?> postExecute(
  1. NodeSpec action,
  2. ActionResult result,
  3. ActionContext context
)

Handles the ActionResult of an executed action and determines the next Action to be executed if any.

Implementation

@protected
Future<NodeSpec?> postExecute(
    NodeSpec action, ActionResult result, ActionContext context) async {
  if (result.returnData != null || action.props["returnName"] != null) {
    final key = action.props["returnName"] ?? "value";
    context.actionContext[key] = result.returnData;
  }

  if (!result.success) {
    if (action.actions["onFailure"] is Map) {
      return NodeSpec.fromMap(action.actions["onFailure"]);
    }

    if (result.failureMessage != null && result.failureMessage!.isNotEmpty) {
      showErrorMessage(result.failureMessage!);
    }
    return null;
  }

  var nextActionSpec = result.nextAction;
  if (nextActionSpec == null && action.actions["nextAction"] != null) {
    nextActionSpec = action.actions["nextAction"];
  }
  return nextActionSpec != null ? NodeSpec.fromMap(nextActionSpec) : null;
}