SingleActivator constructor

const SingleActivator(
  1. LogicalKeyboardKey trigger,
  2. {bool control = false,
  3. bool shift = false,
  4. bool alt = false,
  5. bool meta = false,
  6. bool includeRepeats = true}
)

Triggered when the trigger key is pressed while the modifiers are held.

The trigger should be the non-modifier key that is pressed after all the modifiers, such as LogicalKeyboardKey.keyC as in Ctrl+C. It must not be a modifier key (sided or unsided).

The control, shift, alt, and meta flags represent whether the respective modifier keys should be held (true) or released (false). They default to false.

By default, the activator is checked on all KeyDownEvent events for the trigger key. If includeRepeats is false, only trigger key events which are not KeyRepeatEvents will be considered.

In the following example, the shortcut Control + C increases the counter:
link

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

Implementation

const SingleActivator(
  this.trigger, {
  this.control = false,
  this.shift = false,
  this.alt = false,
  this.meta = false,
  this.includeRepeats = true,
}) : // The enumerated check with `identical` is cumbersome but the only way
     // since const constructors can not call functions such as `==` or
     // `Set.contains`. Checking with `identical` might not work when the
     // key object is created from ID, but it covers common cases.
     assert(
       !identical(trigger, LogicalKeyboardKey.control) &&
       !identical(trigger, LogicalKeyboardKey.controlLeft) &&
       !identical(trigger, LogicalKeyboardKey.controlRight) &&
       !identical(trigger, LogicalKeyboardKey.shift) &&
       !identical(trigger, LogicalKeyboardKey.shiftLeft) &&
       !identical(trigger, LogicalKeyboardKey.shiftRight) &&
       !identical(trigger, LogicalKeyboardKey.alt) &&
       !identical(trigger, LogicalKeyboardKey.altLeft) &&
       !identical(trigger, LogicalKeyboardKey.altRight) &&
       !identical(trigger, LogicalKeyboardKey.meta) &&
       !identical(trigger, LogicalKeyboardKey.metaLeft) &&
       !identical(trigger, LogicalKeyboardKey.metaRight),
     );