isEnabled method

  1. @override
bool isEnabled(
  1. PrioritizedIntents intent, [
  2. BuildContext? context
])
override

Returns true if the action is enabled and is ready to be invoked.

This will be called by the ActionDispatcher before attempting to invoke the action.

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.

Implementation

@override
bool isEnabled(PrioritizedIntents intent, [ BuildContext? context ]) {
  final FocusNode? focus = primaryFocus;
  if  (focus == null || focus.context == null) {
    return false;
  }
  for (final Intent candidateIntent in intent.orderedIntents) {
    final Action<Intent>? candidateAction = Actions.maybeFind<Intent>(
      focus.context!,
      intent: candidateIntent,
    );
    if (candidateAction != null && candidateAction._isEnabled(candidateIntent, context)) {
      _selectedAction = candidateAction;
      _selectedIntent = candidateIntent;
      return true;
    }
  }
  return false;
}