labelsByCallbackId function

ActionLabelResolver labelsByCallbackId(
  1. Map<String, String> labels
)

Runs the host's ActionLabelResolver over every action in a rich-content tree and returns the tree with the resolved labels applied.

Done once, at the top of the renderer, rather than in each component widget: the label lives on the action model, and rewriting it there means buttons, card actions, image actions and swatches all pick the override up without knowing it exists. A null resolver (or a resolver that returns null for everything) hands the original object straight back, so the no-host case allocates nothing. The common case, without the host having to touch the action union: a callback_id → label map in the app's own localized copy.

Worth preferring over a hand-written resolver for one non-obvious reason: CallbackAction collides with Flutter's own CallbackAction from package:flutter/widgets.dart, so a host that pattern-matches on it needs an import hide. This helper keeps that out of app code.

Implementation

ActionLabelResolver labelsByCallbackId(Map<String, String> labels) {
  return (action) => switch (action) {
        CallbackAction(:final callbackId) => labels[callbackId],
        _ => null,
      };
}