accepts method Null safety

  1. @override
bool accepts(
  1. RawKeyEvent event,
  2. RawKeyboard state
)
override

Whether the triggering event and the keyboard state at the time of the event meet required conditions, providing that the event is a triggering event.

For example, for Ctrl-A, it has to check if the event is a KeyDownEvent, if either side of the Ctrl key is pressed, and none of the Shift keys, Alt keys, or Meta keys are pressed; it doesn't have to check if KeyA is pressed, since it's already guaranteed.

This method must not cause any side effects for the state. Typically this is only used to query whether HardwareKeyboard.logicalKeysPressed contains a key.

Since ShortcutActivator accepts all event types, subclasses might want to check the event type in accepts.

See also:

Implementation

@override
bool accepts(RawKeyEvent event, RawKeyboard state) {
  final Set<LogicalKeyboardKey> pressed = state.keysPressed;
  return event is RawKeyDownEvent
    && event.character == character
    && (includeRepeats || !event.repeat)
    && (control == (pressed.contains(LogicalKeyboardKey.controlLeft) || pressed.contains(LogicalKeyboardKey.controlRight)))
    && (meta == (pressed.contains(LogicalKeyboardKey.metaLeft) || pressed.contains(LogicalKeyboardKey.metaRight)));
}