Actions class

A widget that maps Intents to Actions to be used by its descendants when invoking an Action.

Actions are typically invoked using Shortcuts. They can also be invoked using Actions.invoke on a context containing an ambient Actions widget.

This example creates a custom Action subclass ModifyAction for modifying a model, and another, SaveAction for saving it.

This example demonstrates passing arguments to the Intent to be carried to the Action. Actions can get data either from their own construction (like the model in this example), or from the intent passed to them when invoked (like the increment amount in this example).

This example also demonstrates how to use Intents to limit a widget's dependencies on its surroundings. The SaveButton widget defined in this example can invoke actions defined in its ancestor widgets, which can be customized to match the part of the widget tree that it is in. It doesn't need to know about the SaveAction class, only the SaveIntent, and it only needs to know about a value notifier, not the entire model.

link

To create a local project with this code sample, run:
flutter create --sample=widgets.Actions.1 mysample

See also:

  • Shortcuts, a widget used to bind key combinations to Intents.
  • Intent, a class that contains configuration information for running an Action.
  • Action, a class for containing and defining an invocation of a user action.
  • ActionDispatcher, the object that this widget uses to manage actions.
Inheritance

Constructors

Actions({Key? key, ActionDispatcher? dispatcher, required Map<Type, Action<Intent>> actions, required Widget child})
Creates an Actions widget.
const

Properties

actions Map<Type, Action<Intent>>
A map of Intent keys to Action<Intent> objects that defines which actions this widget knows about.
final
child Widget
This widget can only have one child. To lay out multiple children, let this widget's child be a widget such as Row, Column, or Stack, which have a children property, and then provide the children to that widget.
final
dispatcher ActionDispatcher?
The ActionDispatcher object that invokes actions.
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<Actions>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

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

Static Methods

find<T extends Intent>(BuildContext context, {T? intent}) Action<T>
Finds the Action bound to the given intent type T in the given context.
handler<T extends Intent>(BuildContext context, T intent) VoidCallback?
Returns a VoidCallback handler that invokes the bound action for the given intent if the action is enabled, and returns null if the action is not enabled, or no matching action is found.
invoke<T extends Intent>(BuildContext context, T intent) Object?
Invokes the action associated with the given Intent using the Actions widget that most tightly encloses the given BuildContext.
maybeFind<T extends Intent>(BuildContext context, {T? intent}) Action<T>?
Finds the Action bound to the given intent type T in the given context.
maybeInvoke<T extends Intent>(BuildContext context, T intent) Object?
Invokes the action associated with the given Intent using the Actions widget that most tightly encloses the given BuildContext.
of(BuildContext context) ActionDispatcher
Returns the ActionDispatcher associated with the Actions widget that most tightly encloses the given BuildContext.