genUiActionHandler function

VoidCallback? genUiActionHandler(
  1. CatalogItemContext ctx,
  2. Object? actionData
)

Builds a VoidCallback that performs an A2UI action the same way the core Button does.

Returns null when actionData is null, so widgets that treat a null callback as "disabled" keep that behavior when the model omits the action.

Supported shapes of actionData:

  • {"event": {"name": "...", "context": {...}}} resolves context against ctx.dataContext and dispatches a UserActionEvent with sourceComponentId set to ctx.id.
  • {"functionCall": {"call": "...", "args": {...}}} resolves the call through ctx.dataContext.resolve. closeModal pops the current route.

The returned callback never throws: every failure is reported through ctx.reportError and logged with genui's logger. Malformed action data is reported as an A2uiValidationException so the model receives the actual message (genui forwards other error types as a generic internal error).

Implementation

VoidCallback? genUiActionHandler(CatalogItemContext ctx, Object? actionData) {
  if (actionData == null) return null;
  return () {
    unawaited(_perform(ctx, actionData));
  };
}