invokeFromSemantics method

Future<void> invokeFromSemantics(
  1. CommandId id, {
  2. BuildContext? buildContext,
})

invoke for a semantic action — an agent's or assistive technology's activation — whose result carries the outcome. Completes when the command did; throws the command's error when it failed, so the action reports failed; and throws SemanticActionDeclined when the command is disabled or gone, so it reports unsupported rather than completed.

Semantics(
  role: SemanticRole.button,
  label: 'Save',
  actions: const {SemanticAction.activate},
  onAction: (_) => registry.invokeFromSemantics(save, buildContext: context),
  child: saveButton,
)

Implementation

Future<void> invokeFromSemantics(
  CommandId id, {
  BuildContext? buildContext,
}) async {
  if (!semanticOutcomeOf(await invoke(id, buildContext: buildContext))) {
    throw const SemanticActionDeclined();
  }
}