maybeInvoke<T extends Intent> static method

Object? maybeInvoke<T extends Intent>(
  1. BuildContext context,
  2. T intent

Invokes the action associated with the given Intent using the Actions widget that most tightly encloses the given BuildContext.

This method returns the result of invoking the action's Action.invoke method. If no action mapping was found for the specified intent, or if the first action found was disabled, or the action itself returns null from Action.invoke, then this method returns null.

If the given intent doesn't map to an action, then it will look to the next ancestor Actions widget in the hierarchy until it reaches the root. If a suitable Action is found but its Action.isEnabled returns false, the search will stop and this method will return null.


static Object? maybeInvoke<T extends Intent>(
  BuildContext context,
  T intent,
) {
  Object? returnValue;
  _visitActionsAncestors(context, (InheritedElement element) {
    final _ActionsScope actions = element.widget as _ActionsScope;
    final Action<T>? result = _castAction(actions, intent: intent);
    if (result != null && result._isEnabled(intent, context)) {
      // Invoke the action we found using the relevant dispatcher from the Actions
      // element we found.
      returnValue = _findDispatcher(element).invokeAction(result, intent, context);
    return result != null;
  return returnValue;