Action class final
A composable action that can be executed in response to user interaction.
Actions are defined in the CMS and can contain multiple configurations that are executed in sequence. Each configuration can be:
- Awaited or non-awaited
- Parameterized with arguments
- Customized with a title
Example CMS schema:
export const action = defineType({
name: 'action',
fields: [
{name: 'title', type: 'string'},
{name: 'configurations', type: 'array', of: [{type: 'action.config'}]},
],
});
Example usage:
final action = Action(
title: 'Submit Form',
configurations: [
ValidateFormConfig(),
SaveDataConfig(isAwaited: true),
ShowToastConfig(message: 'Saved!'),
],
);
// Execute the action
await action.execute(context, arguments: {'formData': data});
- Annotations
-
- @JsonSerializable()
Constructors
-
Action.new({String? title, List<
ActionConfiguration> ? configurations}) - Creates a new action with optional title and configurations.
-
Action.fromJson(Map<
String, dynamic> json) -
Creates an action from a JSON object.
factory
Properties
-
configurations
→ List<
ActionConfiguration> ? -
List of configurations to execute when the action is triggered.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- isEmpty → bool
-
Returns true if this action has no configurations.
no setter
- isNotEmpty → bool
-
Returns true if this action has at least one configuration.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- title → String?
-
Optional title for the action.
final
Methods
-
execute(
BuildContext context, {Map< String, dynamic> ? arguments}) → FutureOr<void> - Executes all configurations in sequence.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
configurationList(
dynamic json) → dynamic - Converts a JSON array to a list of ActionConfiguration instances.