Action<T extends Intent> class abstract

Base class for an action or command to be performed.

Actions are typically invoked as a result of a user action. For example, the Shortcuts widget will map a keyboard shortcut into an Intent, which is given to an ActionDispatcher to map the Intent to an Action and invoke it.

The ActionDispatcher can invoke an Action on the primary focus, or without regard for focus.

Action Overriding

When using a leaf widget to build a more specialized widget, it's sometimes desirable to change the default handling of an Intent defined in the leaf widget. For instance, TextField's SelectAllTextIntent by default selects the text it currently contains, but in a US phone number widget that consists of 3 different TextFields (area code, prefix and line number), SelectAllTextIntent should instead select the text within all 3 TextFields.

An overridable Action is a special kind of Action created using the Action.overridable constructor. It has access to a default Action, and a nullable override Action. It has the same behavior as its override if that exists, and mirrors the behavior of its defaultAction otherwise.

The Action.overridable constructor creates overridable Actions that use a BuildContext to find a suitable override in its ancestor Actions widget. This can be used to provide a default implementation when creating a general purpose leaf widget, and later override it when building a more specialized widget using that leaf widget. Using the TextField example above, the TextField widget uses an overridable Action to provide a sensible default for SelectAllTextIntent, while still allowing app developers to change that if they add an ancestor Actions widget that maps SelectAllTextIntent to a different Action.

See the article on Using Actions and Shortcuts for a detailed explanation.

See also:

  • Shortcuts, which is a widget that contains a key map, in which it looks up key combinations in order to invoke actions.
  • Actions, which is a widget that defines a map of Intent to Action and allows redefining of actions for its descendants.
  • ActionDispatcher, a class that takes an Action and invokes it, passing a given Intent.
  • Action.overridable for an example on how to make an Action overridable.
Mixed in types
Implementers

Constructors

Action()
Creates an Action.
Action.overridable({required Action<T> defaultAction, required BuildContext context})
Creates an Action that allows itself to be overridden by the closest ancestor Action in the given context that handles the same Intent, if one exists.
factory

Properties

callingAction Action<T>?
The Action overridden by this Action.
no setter
hashCode int
The hash code for this object.
no setterinherited
intentType Type
Gets the type of intent this action responds to.
no setter
isActionEnabled bool
Whether this Action is inherently enabled.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addActionListener(ActionListenerCallback listener) → void
Register a callback to listen for changes to the state of this action.
consumesKey(T intent) bool
Indicates whether this action should treat key events mapped to this action as being "handled" when it is invoked via the key event.
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
invoke(T intent) Object?
Called when the action is to be performed.
isEnabled(T intent) bool
Returns true if the action is enabled and is ready to be invoked.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyActionListeners() → void
Call all the registered listeners.
removeActionListener(ActionListenerCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toKeyEventResult(T intent, covariant Object? invokeResult) KeyEventResult
Converts the result of invoke of this action to a KeyEventResult.
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringShort() String
A brief description of this object, usually just the runtimeType and the hashCode.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited