invokeActionIfEnabled method

(bool, Object?) invokeActionIfEnabled(
  1. covariant Action<Intent> action,
  2. covariant Intent intent, [
  3. BuildContext? context
])

Invokes the given action, passing it the given intent, but only if the action is enabled.

The action will be invoked with the given context, if given, but only if the action is a ContextAction subclass. If no context is given, and the action is a ContextAction, then the context from the primaryFocus is used.

The return value has two components. The first is a boolean indicating if the action was enabled (as per Action.isEnabled). If this is false, the second return value is null. Otherwise, the second return value is the object returned from Action.invoke.

Consider using invokeAction if the enabled state of the action is not in question; this avoids calling Action.isEnabled redundantly.

Implementation

(bool, Object?) invokeActionIfEnabled(
  covariant Action<Intent> action,
  covariant Intent intent, [
  BuildContext? context,
]) {
  final BuildContext? target = context ?? primaryFocus?.context;
  if (action._isEnabled(intent, target)) {
    return (true, action._invoke(intent, target));
  }
  return (false, null);
}