handleRawKeyEvent method

bool handleRawKeyEvent(
  1. RawKeyEvent event

Process a new RawKeyEvent by recording the state changes and dispatching to listeners.


bool handleRawKeyEvent(RawKeyEvent event) {
  if (event is RawKeyDownEvent) {
    _keysPressed[event.physicalKey] = event.logicalKey;
  } else if (event is RawKeyUpEvent) {
    // Use the physical key in the key up event to find the physical key from
    // the corresponding key down event and remove it, even if the logical
    // keys don't match.
  // Make sure that the modifiers reflect reality, in case a modifier key was
  // pressed/released while the app didn't have focus.
    event is! RawKeyDownEvent || _keysPressed.isNotEmpty,
    'Attempted to send a key down event when no keys are in keysPressed. '
    "This state can occur if the key event being sent doesn't properly "
    'set its modifier flags. This was the event: $event and its data: '
  // Send the event to passive listeners.
  for (final ValueChanged<RawKeyEvent> listener in List<ValueChanged<RawKeyEvent>>.of(_listeners)) {
    try {
      if (_listeners.contains(listener)) {
    } catch (exception, stack) {
      InformationCollector? collector;
      assert(() {
        collector = () => <DiagnosticsNode>[
          DiagnosticsProperty<RawKeyEvent>('Event', event),
        return true;
        exception: exception,
        stack: stack,
        library: 'services library',
        context: ErrorDescription('while processing a raw key listener'),
        informationCollector: collector,

  return false;