Skip to content

Exception in the console when pressing CMD (on Mac) while the application is running #170290

Closed as duplicate of#125975
@Calin-Cosma

Description

@Calin-Cosma

Steps to reproduce

Running the desktop application, after it loads, I'm pressing CMD without doing anything else.
There's no code that tries to deal with shortcuts. No reference to Shortcuts or Intent classes.

Expected results

I would expect nothing to happen.

Actual results

I get this in the console

======== 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#aef58(physicalKey: PhysicalKeyboardKey#f2ed2(usbHidUsage: "0x000700e3", debugName: "Meta Left"), logicalKey: LogicalKeyboardKey#e3a44(keyId: "0x200000106", keyLabel: "Meta Left", debugName: "Meta Left"), character: null, timeStamp: 211:51:58.778582)
'package:flutter/src/services/hardware_keyboard.dart':
Failed assertion: line 516 pos 11: '!_pressedKeys.containsKey(event.physicalKey)'


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> (package:flutter/src/services/hardware_keyboard.dart:516:11)
#3      HardwareKeyboard._assertEventIsRegular (package:flutter/src/services/hardware_keyboard.dart:536:6)
#4      HardwareKeyboard.handleKeyEvent (package:flutter/src/services/hardware_keyboard.dart:660:5)
#5      KeyEventManager.handleRawKeyMessage (package:flutter/src/services/hardware_keyboard.dart:1184:37)
#6      BasicMessageChannel.setMessageHandler.<anonymous closure> (package:flutter/src/services/platform_channel.dart:261:49)
#7      _DefaultBinaryMessenger.setMessageHandler.<anonymous closure> (package:flutter/src/services/binding.dart:653:35)
#8      _invoke2 (dart:ui/hooks.dart:363:13)
#9      _ChannelCallbackRecord.invoke (dart:ui/channel_buffers.dart:45:5)
#10     _Channel.push (dart:ui/channel_buffers.dart:136:31)
#11     ChannelBuffers.push (dart:ui/channel_buffers.dart:344:17)
#12     PlatformDispatcher._dispatchPlatformMessage (dart:ui/platform_dispatcher.dart:802:22)
#13     _dispatchPlatformMessage (dart:ui/hooks.dart:277:31)
(elided 2 frames from class _AssertionError)
====================================================================================================

Code sample

It doesn't always happen and there's no reference to my code in the stacktrace.
Unfortunately I can't consistently reproduce it.

With the same code, if I restart the app from Adroid Studio, the issue disappears, only to show up again later on, after changing my code and after a number of restarts of the app from Android Studio.

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
$ flutter doctor -v
[✓] Flutter (Channel stable, 3.32.2, on macOS 15.5 24F74 darwin-arm64, locale en-BE) [325ms]
    • Flutter version 3.32.2 on channel stable at /opt/homebrew/Caskroom/flutter/3.29.3/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 8defaa71a7 (5 days ago), 2025-06-04 11:02:51 -0700
    • Engine revision 1091508939
    • Dart version 3.8.1
    • DevTools version 2.45.1

[✓] Android toolchain - develop for Android devices (Android SDK version 36.0.0) [1,106ms]
    • Android SDK at /Users/me/Library/Android/sdk
    • Platform android-33, build-tools 36.0.0
    • ANDROID_HOME = /Users/me/Library/Android/sdk
    • Java binary at: /Users/me/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
      This is the JDK bundled with the latest Android Studio installation on this machine.
      To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 21.0.6+-13368085-b895.109)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.4) [695ms]
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16F6
    • CocoaPods version 1.16.2

[✓] Chrome - develop for the web [46ms]
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2024.3) [45ms]
    • Android Studio at /Users/me/Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 21.0.6+-13368085-b895.109)

[✓] IntelliJ IDEA Ultimate Edition (version 2025.1.2) [44ms]
    • IntelliJ at /Users/me/Applications/IntelliJ IDEA Ultimate.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin version 251.25410.28

[✓] Connected device (2 available) [6.6s]
    • macOS (desktop) • macos  • darwin-arm64   • macOS 15.5 24F74 darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 137.0.7151.69

[✓] Network resources [261ms]
    • All expected network resources are available.

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions