Skip to content

A KeyUpEvent is dispatched, but the state shows that the physical key is not pressed when hitting Backspace the first time #122441

@lukehutch

Description

@lukehutch

I get the following error the first time I hit Backspace in a multi-line TextField:

16: '_pressedKeys.containsKey(event.physicalKey)': A KeyUpEvent is dispatched, but the state shows that the physical key is not 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: KeyUpEvent#73576(physicalKey: PhysicalKeyboardKey#e6f4b(usbHidUsage: "0x0007002a", debugName: "Backspace"), logicalKey: LogicalKeyboardKey#147d9(keyId: "0x100000008", keyLabel: "Backspace", debugName: "Backspace"), character: null, timeStamp: 0:02:47.131935, synthesized)
hardware_keyboard.dart:432
E/flutter (25509): #0      _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61)
E/flutter (25509): #1      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5)
E/flutter (25509): #2      HardwareKeyboard._assertEventIsRegular.<anonymous closure>
hardware_keyboard.dart:432
E/flutter (25509): #3      HardwareKeyboard._assertEventIsRegular
hardware_keyboard.dart:443
E/flutter (25509): #4      HardwareKeyboard.handleKeyEvent
hardware_keyboard.dart:535
E/flutter (25509): #5      KeyEventManager.handleKeyData
hardware_keyboard.dart:881
E/flutter (25509): #6      PlatformDispatcher._keyDataListener.<anonymous closure>.<anonymous closure> (dart:ui/platform_dispatcher.dart:430:41)
E/flutter (25509): #7      _invoke1 (dart:ui/hooks.dart:164:13)
E/flutter (25509): #8      PlatformDispatcher._keyDataListener.<anonymous closure> (dart:ui/platform_dispatcher.dart:428:7)

It only happens once, and subsequently pressing Backspace doesn't trigger the error.

Steps to Reproduce

        TextField(
          controller: controller,
          keyboardType: TextInputType.multiline,
          maxLines: null,
          autofocus: true,
          maxLength: 40,
        ),

where controller = TextEditingController()..text('Some\ninitial\nmultiline\ntext') that is properly disposed when dispose() is called on the widget.

Expected results:

Should be no exception

Actual results:

I get an exception the first time I hit Backspace when the widget is shown

Details
Nothing relevant
$ flutter doctor -v
[✓] Flutter (Channel stable, 3.7.5, on Fedora Linux 36 (Workstation Edition)
    6.1.14-100.fc36.x86_64, locale en_US.utf8)
    • Flutter version 3.7.5 on channel stable at /opt/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision c07f788888 (2 weeks ago), 2023-02-22 17:52:33 -0600
    • Engine revision 0f359063c4
    • Dart version 2.19.2
    • DevTools version 2.20.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at /home/luke/Android/Sdk
    • Platform android-33, build-tools 33.0.1
    • Java binary at: /opt/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build
      11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • clang version 14.0.5 (Fedora 14.0.5-2.fc36)
    • cmake version 3.25.2
    • ninja version 1.10.2
    • pkg-config version 1.8.0

[✓] Android Studio (version 2021.3)
    • Android Studio at /opt/android-studio
    • Flutter plugin version 71.0.3
    • Dart plugin version 213.7433
    • Java version OpenJDK Runtime Environment (build
      11.0.13+0-b1751.21-8125866)

[✓] VS Code (version 1.76.0)
    • VS Code at /usr/share/code
    • Flutter extension version 3.60.0

[✓] Connected device (3 available)
    • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64    • Android 13
      (API 33) (emulator)
    • Linux (desktop)              • linux         • linux-x64      • Fedora
      Linux 36 (Workstation Edition) 6.1.14-100.fc36.x86_64
    • Chrome (web)                 • chrome        • web-javascript • Google
      Chrome 110.0.5481.177

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemsc: crashStack traces logged to the consolefound in release: 3.7Found to occur in 3.7found in release: 3.9Found to occur in 3.9frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-androidAndroid applications specificallyr: fixedIssue is closed as already fixed in a newer version

Type

No type

Projects

Status

Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions