invoke method Null safety

  1. @protected
  2. @override
Object? invoke(
  1. T intent,
  2. [BuildContext? context]
)
protected">@protectedoverride

Called when the action is to be performed.

This is called by the ActionDispatcher when an action is invoked via Actions.invoke, or when an action is invoked using ActionDispatcher.invokeAction directly.

This method is only meant to be invoked by an ActionDispatcher, or by its subclasses, and only when isEnabled is true.

The optional context parameter is the context of the invocation of the action, and in the case of an action invoked by a ShortcutManager, via a Shortcuts widget, will be the context of the Shortcuts widget.

When overriding this method, the returned value can be any Object, but changing the return type of the override to match the type of the returned value provides more type safety.

For instance, if your override of invoke returns an int, then define it like so:

class IncrementIntent extends Intent {
  const IncrementIntent({this.index});

  final int index;
}

class MyIncrementAction extends ContextAction<IncrementIntent> {
  @override
  int invoke(IncrementIntent intent, [BuildContext context]) {
    return intent.index + 1;
  }
}

Implementation

@protected
@override
Object? invoke(T intent, [BuildContext? context]);