actionButtonEntry top-level property

WidgetEntry actionButtonEntry
final

Implementation

final WidgetEntry actionButtonEntry = WidgetEntry( // Use 'final' for consistency
  // The builder function that creates an instance of the _ActionButtonWidget.
  // It extracts the necessary parameters from the JSON map.
  builder: (BuildContext context, Map<String, dynamic> params, SendCommandCallback sendCommand) {
    // Extract parameters from the JSON. Provide default values if they are missing.
    final String label = params['label'] ?? 'Action';
    final String commandType = params['commandType'] ?? 'unknown_action';
    // Safely cast args to Map<String, dynamic>. Provide an empty map as a default.
    final Map<String, dynamic> commandArgs = (params['args'] is Map)
        ? Map<String, dynamic>.from(params['args'])
        : {};

    // Return an instance of your widget, passing the extracted parameters and the callback.
    return _ActionButtonWidget(
      label: label,
      commandType: commandType,
      commandArgs: commandArgs,
      sendCommand: sendCommand, // Pass the callback received by the builder
    );
  },
  // Metadata describing the action_button widget.
  metadata: EmbeddedWidgetMetadata(
    description: 'A clickable button that sends a command to the system.',
    parameterSchema: {
      'label': 'string (required) - The text displayed on the button.',
      'commandType': 'string (required) - The type of command to send.',
      'args': 'map (optional) - Additional arguments for the command.'
    },
  ),
);