Skip to content

A KeyDownEvent is dispatched, but the state shows that the physical key is already pressed. #172153

Description

@richard457

Steps to reproduce

  1. Run flutter app
  2. While app loading also press on keyboard before app finish to start

Expected results

the error A KeyDownEvent is dispatched, but the state shows that the physical key is already pressed. should not be shown and should not block the app to start.

Actual results

The error A KeyDownEvent is dispatched, but the state shows that the physical key is already pressed. shows and the app is black blank.

Code sample

Any flutter sample app would trigger the same error on desktop

Screenshots or Video

N/A

Logs

Logs
════════ Exception caught by services library ══════════════════════════════════
The following assertion was thrown during a platform message callback:
A KeyDownEvent is dispatched, but the state shows that the physical key is already pressed. If this occurs in real application, please report this bug to Flutter. If this occurs in unit tests, please ensure that simulated events follow Flutter's event model as documented in `HardwareKeyboard`. This was the event: KeyDownEvent#d2cbe(physicalKey: PhysicalKeyboardKey#86a89(usbHidUsage: "0x00070008", debugName: "Key E"), logicalKey: LogicalKeyboardKey#1e0f5(keyId: "0x00000065", keyLabel: "E", debugName: "Key E"), character: "e", timeStamp: 68:39:13.782805)
'package:flutter/src/services/hardware_keyboard.dart':
hardware_keyboard.dart:1
Failed assertion: line 530 pos 11: '!_pressedKeys.containsKey(event.physicalKey)'

2

Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=02_bug.yml

When the exception was thrown, this was the stack
#2      HardwareKeyboard._assertEventIsRegular.<anonymous closure>
hardware_keyboard.dart:530
#3      HardwareKeyboard._assertEventIsRegular
hardware_keyboard.dart:550
#4      HardwareKeyboard.handleKeyEvent
hardware_keyboard.dart:681
#5      KeyEventManager.handleRawKeyMessage
hardware_keyboard.dart:1220
#6      BasicMessageChannel.setMessageHandler.<anonymous closure>
platform_channel.dart:261
#7      _DefaultBinaryMessenger.setMessageHandler.<anonymous closure>
binding.dart:653
#8      _invoke2 (dart:ui/hooks.dart:363:13)
#9      _ChannelCallbackRecord.invoke (dart:ui/channel_buffers.dart:45:5)
#10     _Channel._drainStep (dart:ui/channel_buffers.dart:229:31)
(elided 12 frames from class _AssertionError and dart:async)

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.32.5, on macOS 15.5 24F74 darwin-x64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0-rc3)
[✓] Xcode - develop for iOS and macOS (Xcode 16.0)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.1)
[✓] IntelliJ IDEA Ultimate Edition (version 2024.2.0.2)
[✓] IntelliJ IDEA Community Edition (version 2024.1.4)
[✓] VS Code (version 1.101.2)
[✓] Connected device (2 available)

Metadata

Metadata

Assignees

No one assigned

    Labels

    r: duplicateIssue is closed as a duplicate of an existing issue

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions