Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null check operator used on a null _rawKeyboard.lookUpLayout(physicalKey)! #88236

Closed
narumi147 opened this issue Aug 15, 2021 · 15 comments
Closed
Labels
a: null-safety Support for Dart's null safety feature a: production Issues experienced in live production apps a: text input Entering text in a text field or keyboard related problems c: regression It was better in the past than it is now framework flutter/packages/flutter repository. See also f: labels. platform-android Android applications specifically r: fixed Issue is closed as already fixed in a newer version

Comments

@narumi147
Copy link

Sorry I cannot reproduce it, it is collected from a small amount of app users' crash feedback. All are android devices.

Error:
Null check operator used on a null value
Stack trace:
#0 KeyEventManager._convertRawEventAndStore (package:flutter/src/services/hardware_keyboard.dart:892)
#1 RawKeyboard.handleRawKeyEvent (package:flutter/src/services/raw_keyboard.dart:677)
#2 KeyEventManager.handleRawKeyMessage (package:flutter/src/services/hardware_keyboard.dart:818)
#3 BasicMessageChannel.setMessageHandler.<anonymous closure> (package:flutter/src/services/platform_channel.dart:73)
#4 BasicMessageChannel.setMessageHandler.<anonymous closure> (package:flutter/src/services/platform_channel.dart:72)
#5 _DefaultBinaryMessenger.setMessageHandler.<anonymous closure> (package:flutter/src/services/binding.dart:379)
#6 _DefaultBinaryMessenger.setMessageHandler.<anonymous closure> (package:flutter/src/services/binding.dart:376)
#7 _invoke2.<anonymous closure> (dart:ui/hooks.dart:205)
#8 _rootRun (dart:async/zone.dart:1428)
#9 _CustomZone.run (dart:async/zone.dart:1328)
#10 _CustomZone.runGuarded (dart:async/zone.dart:1236)
#11 _invoke2 (dart:ui/hooks.dart:204)
#12 _ChannelCallbackRecord.invoke (dart:ui/channel_buffers.dart:42)
#13 _Channel.push (dart:ui/channel_buffers.dart:132)
#14 ChannelBuffers.push (dart:ui/channel_buffers.dart:329)
#15 PlatformDispatcher._dispatchPlatformMessage (dart:ui/platform_dispatcher.dart:544)
#16 _dispatchPlatformMessage (dart:ui/hooks.dart:92)

for (final PhysicalKeyboardKey key in _rawKeyboard.physicalKeysPressed.difference(physicalKeysPressed)) {
_keyEventsSinceLastMessage.add(KeyDownEvent(
physicalKey: key,
logicalKey: _rawKeyboard.lookUpLayout(physicalKey)!,
timeStamp: timeStamp,
synthesized: true,
));
}

Built using Flutter (Channel beta, 2.5.0-5.1.pre, on Microsoft Windows [Version 10.0.19043.1110], locale zh-CN)

flutter doctor -v
[✓] Flutter (Channel beta, 2.5.0-5.1.pre, on Microsoft Windows [Version 10.0.19043.1110], locale zh-CN)
    • Flutter version 2.5.0-5.1.pre at D:\Projects\sdk\flutter
    • Upstream repository https://mirrors.tuna.tsinghua.edu.cn/git/flutter-sdk.git
    • Framework revision 65cf7de5f4 (3 days ago), 2021-08-11 15:48:01 -0700
    • Engine revision fbeb7e22bd
    • Dart version 2.14.0 (build 2.14.0-377.4.beta)
    • Pub download mirror https://pub.flutter-io.cn
    • Flutter download mirror https://storage.flutter-io.cn

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at D:\Projects\sdk\Android\Sdk
    • Platform android-30, build-tools 30.0.3
    • ANDROID_HOME = D:\Projects\sdk\Android\Sdk
    • Java binary at: C:\Users\narumi\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-1\202.7486908\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)
    • All Android licenses accepted.

[✗] Chrome - develop for the web (Cannot find Chrome executable at .\Google\Chrome\Application\chrome.exe)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Visual Studio - develop for Windows (Visual Studio Enterprise 2019 16.8.3)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise
    • Visual Studio Enterprise 2019 version 16.8.30804.86
    • Windows 10 SDK version 10.0.18362.0

[✓] Android Studio (version 4.2)
    • Android Studio at C:\Users\narumi\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-1\202.7486908
    • Flutter plugin version 59.0.1
    • Dart plugin version 202.8531
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)

[✓] VS Code (version 1.57.1)
    • VS Code at C:\Users\narumi\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.24.0

[✓] Connected device (2 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.19043.1110]
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 92.0.902.62

! Doctor found issues in 1 category.
@narumi147 narumi147 changed the title Null check operator used on a null value KeyEventManager._convertRawEventAndStore: Null check operator used on a null _rawKeyboard.lookUpLayout(physicalKey)! Aug 15, 2021
@TahaTesser TahaTesser added the in triage Presently being triaged by the triage team label Aug 17, 2021
@TahaTesser
Copy link
Member

Hi @narumishi
Can you please provide your pubspec.yaml, the list of affected devices and if possible your flutter run --release --verbose running on the same OS version as the affected devices.
Thank you

@TahaTesser TahaTesser added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Aug 17, 2021
@narumi147
Copy link
Author

narumi147 commented Aug 17, 2021

@TahaTesser You can check pubspec.yaml and pubspec.lock here: https://github.com/chaldea-center/chaldea/blob/21b308555fc3ad507df0ffd645343b072e478f61/pubspec.yaml

The problem is occurred just in flutter beta, 2.5.0-5.1.pre, I didn't receive any report of this built by 2.4.0-4.1.pre.

I cannot reproduce the problem on my own android device and even don't how to reproduce it. The only thing I know is that users are inputing text......

Every day, about 5 crash reports received while near 800 active devices in total.

some devices
Device parameters:
id: HUAWEILIO-AN00
board: LIO
bootloader: unknown
brand: HUAWEI
device: HWLIO
display: LIO-AN00 2.0.0.138(C00E130R5P5)
fingerprint: HUAWEI/LIO-AN00/HWLIO:10/HUAWEILIO-AN00/102.0.0.138C00:user/release-keys
hardware: kirin990
host: cn-central-hcd-2a-6aff77b631625990365105-8588f69d65-p7sf2
isPhysicalDevice: true
manufacturer: HUAWEI
model: LIO-AN00
product: LIO-AN00
tags: release-keys
type: user
versionBaseOs: 
versionCodename: REL
versionIncremental: 102.0.0.138C00
versionPreviewSdk: 0
versionRelease: 10
versionSdk: 29
versionSecurityPatch: 2020-11-01

Device parameters:
id: HUAWEIELE-L29
board: ELE
bootloader: unknown
brand: HUAWEI
device: HWELE
display: ELE-L29 10.1.0.150(C431E22R2P5)
fingerprint: HUAWEI/ELE-L29EEA/HWELE:10/HUAWEIELE-L29/10.1.0.150C431:user/release-keys
hardware: kirin980
host: cn-central-1b-a687fa2531596186059456-3543762350-474m6
isPhysicalDevice: true
manufacturer: HUAWEI
model: ELE-L29
product: ELE-L29EEA
tags: release-keys
type: user
versionBaseOs: HUAWEI/ELE-L29EEA/HWELE:10/HUAWEIELE-L29/10.1.0.140C431:user/release-keys
versionCodename: REL
versionIncremental: 10.1.0.150C431
versionPreviewSdk: 0
versionRelease: 10
versionSdk: 29
versionSecurityPatch: 2020-08-01

Device parameters:
id: QP1A.190711.020
board: exynos7904
bootloader: M205GDXU7CUD2
brand: samsung
device: m20lte
display: QP1A.190711.020.M205GDXU7CUD2
fingerprint: samsung/m20ltedx/m20lte:10/QP1A.190711.020/M205GDXU7CUD2:user/release-keys
hardware: exynos7904
host: VPDJR204
isPhysicalDevice: true
manufacturer: samsung
model: SM-M205G
product: m20ltedx
tags: release-keys
type: user
versionBaseOs: 
versionCodename: REL
versionIncremental: M205GDXU7CUD2
versionPreviewSdk: 0
versionRelease: 10
versionSdk: 29
versionSecurityPatch: 2021-04-01
Device parameters:
id: RP1A.200720.012
board: exynos9820
bootloader: G975FXXSBFUF3
brand: samsung
device: beyond2
display: RP1A.200720.012.G975FXXSBFUF3
fingerprint: samsung/beyond2ltexx/beyond2:11/RP1A.200720.012/G975FXXSBFUF3:user/release-keys
hardware: exynos9820
host: 21DJ7D15
isPhysicalDevice: true
manufacturer: samsung
model: SM-G975F
product: beyond2ltexx
tags: release-keys
type: user
versionBaseOs: samsung/beyond2ltexx/beyond2:11/RP1A.200720.012/G975FXXUAFUE3:user/release-keys
versionCodename: REL
versionIncremental: G975FXXSBFUF3
versionPreviewSdk: 0
versionRelease: 11
versionSdk: 30
versionSecurityPatch: 2021-07-01

Device parameters:
id: QP1A.190711.020
board: msmnile
bootloader: G9730ZCU4CTG2
brand: samsung
device: beyond1q
display: QP1A.190711.020.G9730ZCU4CTG2
fingerprint: samsung/beyond1qltezc/beyond1q:10/QP1A.190711.020/G9730ZCU4CTG2:user/release-keys
hardware: qcom
host: SWDH7904
isPhysicalDevice: true
manufacturer: samsung
model: SM-G9730
product: beyond1qltezc
tags: release-keys
type: user
versionBaseOs: 
versionCodename: REL
versionIncremental: G9730ZCU4CTG2
versionPreviewSdk: 0
versionRelease: 10
versionSdk: 29
versionSecurityPatch: 2020-08-01

Device parameters:
id: HUAWEITAS-AL00
board: TAS
bootloader: unknown
brand: HUAWEI
device: HWTAS
display: TAS-AL00 11.0.0.180(C00E180R5P11)
fingerprint: HUAWEI/TAS-AL00/HWTAS:10/HUAWEITAS-AL00/11.0.0.180C00:user/release-keys
hardware: kirin990
host: cn-east-hcd-4a-769e4cbda1619805713044-69b57b57bf-7l8t7
isPhysicalDevice: true
manufacturer: HUAWEI
model: TAS-AL00
product: TAS-AL00
tags: release-keys
type: user
versionBaseOs: 
versionCodename: REL
versionIncremental: 11.0.0.180C00
versionPreviewSdk: 0
versionRelease: 10
versionSdk: 29
versionSecurityPatch: 2020-11-01

Device parameters:
id: QP1A.190711.020
board: exynos7904
bootloader: A307GUBS4BUC1
brand: samsung
device: a30s
display: QP1A.190711.020.A307GUBS4BUC1
fingerprint: samsung/a30sub/a30s:10/QP1A.190711.020/A307GUBS4BUC1:user/release-keys
hardware: exynos7904
host: SWDH7019
isPhysicalDevice: true
manufacturer: samsung
model: SM-A307G
product: a30sub
tags: release-keys
type: user
versionBaseOs: samsung/a30sub/a30s:10/QP1A.190711.020/A307GUBU4BTJ3:user/release-keys
versionCodename: REL
versionIncremental: A307GUBS4BUC1
versionPreviewSdk: 0
versionRelease: 10
versionSdk: 29
versionSecurityPatch: 2021-03-01
Device parameters:
id: QP1A.190711.020
board: exynos7904
bootloader: A307GUBS4BUC1
brand: samsung
device: a30s
display: QP1A.190711.020.A307GUBS4BUC1
fingerprint: samsung/a30sub/a30s:10/QP1A.190711.020/A307GUBS4BUC1:user/release-keys
hardware: exynos7904
host: SWDH7019
isPhysicalDevice: true
manufacturer: samsung
model: SM-A307G
product: a30sub
tags: release-keys
type: user
versionBaseOs: samsung/a30sub/a30s:10/QP1A.190711.020/A307GUBU4BTJ3:user/release-keys
versionCodename: REL
versionIncremental: A307GUBS4BUC1
versionPreviewSdk: 0
versionRelease: 10
versionSdk: 29
versionSecurityPatch: 2021-03-01

Device parameters:
id: HUAWEITAS-AN00
board: TAS
bootloader: unknown
brand: HUAWEI
device: HWTAS
display: TAS-AN00 2.0.0.138(C00E130R6P5)
fingerprint: HUAWEI/TAS-AN00/HWTAS:10/HUAWEITAS-AN00/102.0.0.138C00:user/release-keys
hardware: kirin990
host: cn-central-hcd-2a-6aff77b631625990365105-8588f69d65-p7sf2
isPhysicalDevice: true
manufacturer: HUAWEI
model: TAS-AN00
product: TAS-AN00
tags: release-keys
type: user
versionBaseOs: 
versionCodename: REL
versionIncremental: 102.0.0.138C00
versionPreviewSdk: 0
versionRelease: 10
versionSdk: 29
versionSecurityPatch: 2020-11-01

Device parameters:
id: NRD90M
board: universal7420
bootloader: N920KKKS2DTJ2
brand: samsung
device: nobleltektt
display: NRD90M.N920KKKS2DTJ2
fingerprint: samsung/nobleltektt/nobleltektt:7.0/NRD90M/N920KKKS2DTJ2:user/release-keys
hardware: samsungexynos7420
host: SWDH7912
isPhysicalDevice: true
manufacturer: samsung
model: SM-N920K
product: nobleltektt
tags: release-keys
type: user
versionBaseOs: samsung/nobleltektt/nobleltektt:7.0/NRD90M/N920KKKU2DRG3:user/release-keys
versionCodename: REL
versionIncremental: N920KKKS2DTJ2
versionPreviewSdk: 0
versionRelease: 7.0
versionSdk: 24
versionSecurityPatch: 2018-08-01

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Aug 17, 2021
@TahaTesser TahaTesser added a: null-safety Support for Dart's null safety feature a: production Issues experienced in live production apps a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. passed first triage platform-android Android applications specifically c: regression It was better in the past than it is now and removed in triage Presently being triaged by the triage team labels Aug 18, 2021
@stuartmorgan
Copy link
Contributor

@dkwingsmt This looks like code you added recently?

@TahaTesser TahaTesser changed the title KeyEventManager._convertRawEventAndStore: Null check operator used on a null _rawKeyboard.lookUpLayout(physicalKey)! Null check operator used on a null _rawKeyboard.lookUpLayout(physicalKey)!` Aug 19, 2021
@TahaTesser TahaTesser changed the title Null check operator used on a null _rawKeyboard.lookUpLayout(physicalKey)!` Null check operator used on a null _rawKeyboard.lookUpLayout(physicalKey)! Aug 19, 2021
@dkwingsmt
Copy link
Contributor

dkwingsmt commented Aug 19, 2021

Yes this was added recently. Although this null assertion really should be safe.
@narumishi Does you app call RawKeyboard.clearKeysPressed() (which you shouldn't)? A previous report of the same error message turned out to be this problem.

Also, although it'll be hard to pinpoint the cause without a reliable reproduction, in the future this problem will eventually be avoided since we plan to implement Android's hardware keyboard handler as a high priority task, at which time this code will no longer be called.

@narumi147
Copy link
Author

@dkwingsmt nope, I never called clearKeysPressed. The only things may related with keybord:

  • update text and selection through controller
  • move focus next or previous at certain action

@dkwingsmt
Copy link
Contributor

I can't think of any case that the result of lookUpLayout can be null here, since physicalKeysPressed has literally just ensured that the key's pressed. Let me know if you can come up with a reproduction step. In the meantime I'll raise the priority for the keyboard embedding for Android, after which this should no longer be a problem.

@narumi147
Copy link
Author

Another similar issue I encountered when developing. See the error below. The error is sometimes raised suddenly(which means I can't reproduce it), and then every keyboard input will raise the same error. I need to hot-restart to fix it.

I'm not sure this is related or not. It's on macOS.

======== Exception caught by services library ======================================================
The following assertion was thrown during a platform message callback:
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#89ded(physicalKey: PhysicalKeyboardKey#700e3(usbHidUsage: "0x000700e3", debugName: "Meta Left"), logicalKey: LogicalKeyboardKey#00106(keyId: "0x200000106", keyLabel: "Meta Left", debugName: "Meta Left"), character: null, timeStamp: 312:53:55.455557)
'package:flutter/src/services/hardware_keyboard.dart':
Failed assertion: line 441 pos 16: '_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=2_bug.md

When the exception was thrown, this was the stack: 
#2      HardwareKeyboard._assertEventIsRegular.<anonymous closure> (package:flutter/src/services/hardware_keyboard.dart:441:16)
#3      HardwareKeyboard._assertEventIsRegular (package:flutter/src/services/hardware_keyboard.dart:452:6)
#4      HardwareKeyboard.handleKeyEvent (package:flutter/src/services/hardware_keyboard.dart:543:5)
#5      KeyEventManager.handleRawKeyMessage (package:flutter/src/services/hardware_keyboard.dart:821:35)
#6      BasicMessageChannel.setMessageHandler.<anonymous closure> (package:flutter/src/services/platform_channel.dart:73:49)
#7      BasicMessageChannel.setMessageHandler.<anonymous closure> (package:flutter/src/services/platform_channel.dart:72:47)
#8      _DefaultBinaryMessenger.setMessageHandler.<anonymous closure> (package:flutter/src/services/binding.dart:379:35)
#9      _DefaultBinaryMessenger.setMessageHandler.<anonymous closure> (package:flutter/src/services/binding.dart:376:46)
#10     _invoke2.<anonymous closure> (dart:ui/hooks.dart:205:15)
#14     _invoke2 (dart:ui/hooks.dart:204:10)
#15     _ChannelCallbackRecord.invoke (dart:ui/channel_buffers.dart:42:5)
#16     _Channel.push (dart:ui/channel_buffers.dart:132:31)
#17     ChannelBuffers.push (dart:ui/channel_buffers.dart:329:17)
#18     PlatformDispatcher._dispatchPlatformMessage (dart:ui/platform_dispatcher.dart:544:22)
#19     _dispatchPlatformMessage (dart:ui/hooks.dart:92:31)
(elided 5 frames from class _AssertionError and dart:async)
====================================================================================================
flutter doctor -v
[✓] Flutter (Channel beta, 2.5.0-5.1.pre, on macOS 11.3.1 20E241 darwin-x64, locale en-CN)
    • Flutter version 2.5.0-5.1.pre at /Users/narumi/Library/flutter-stable
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 65cf7de5f4 (10 days ago), 2021-08-11 15:48:01 -0700
    • Engine revision fbeb7e22bd
    • Dart version 2.14.0 (build 2.14.0-377.4.beta)
    • Pub download mirror https://pub.flutter-io.cn
    • Flutter download mirror https://storage.flutter-io.cn

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at /Users/narumi/Library/Android/sdk
    • Platform android-30, build-tools 30.0.2
    • Java binary at: /Users/narumi/Library/Application
      Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/202.7486908/Android
      Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.4, Build version 12D4e
    • CocoaPods version 1.10.1

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

[✓] Android Studio (version 4.2)
    • Android Studio at /Users/narumi/Library/Application
      Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/202.7486908/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 11.0.8+10-b944.6916264)

[✓] Android Studio (version 4.2)
    • Android Studio at /Users/narumi/Library/Application
      Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/202.7486908/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 11.0.8+10-b944.6916264)

[✓] VS Code (version 1.59.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.25.0

[!] Proxy Configuration
    • HTTP_PROXY is set
    ! NO_PROXY is not set

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-x64     • macOS 11.3.1 20E241 darwin-x64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 92.0.4515.159

! Doctor found issues in 1 category.

@valtbarbos
Copy link

valtbarbos commented Aug 21, 2021

There are some ways to reproduce in some environments.

Using an android device via USB with scrcpy (https://github.com/Genymobile/scrcpy).

Using the computer keyboard (don't happens using the android keyboard with mouse) on the TextFormField will throw "Another exception was thrown: Null check operator used on a null value".

@dkwingsmt
Copy link
Contributor

For anyone who can reproduce this issue, can you check if #88967 fixes the issue?

@dkwingsmt
Copy link
Contributor

dkwingsmt commented Aug 31, 2021

Considering this issue fixed via #88967. Feel free to report and/or reopen if similar issues occur.

@TahaTesser TahaTesser added the r: fixed Issue is closed as already fixed in a newer version label Aug 31, 2021
@jmagman
Copy link
Member

jmagman commented Sep 13, 2021

Adding cp request label for evaluation, requested by @untp in #89913.

@silvinhodev
Copy link

silvinhodev commented Sep 15, 2021

For anyone who can reproduce this issue, can you check if #88967 fixes the issue?

Hi, here this issue is evident when using a notebook keyboard, after applying fixes, working flawless! (no more issues)

flutter doctor -v
[✓] Flutter (Channel stable, 2.5.0, on Ubuntu 20.04.2 LTS 5.11.0-34-generic,
    locale pt_BR.UTF-8)
    • Flutter version 2.5.0 at /home/binho/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 4cc385b4b8 (8 days ago), 2021-09-07 23:01:49 -0700
    • Engine revision f0826da7ef
    • Dart version 2.14.0

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /home/binho/Android/Sdk
    • Platform android-30, build-tools 30.0.3
    • Java binary at: /usr/local/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
    • All Android licenses accepted.

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

[✓] Android Studio (version 2020.3)
    • Android Studio at /usr/local/android-studio
    • Flutter plugin version 58.0.2
    • Dart plugin version 203.8292
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)

[✓] VS Code
    • VS Code at /snap/code/current
    • Flutter extension version 3.26.0

[✓] Connected device (2 available)
    • SM G930F (mobile) • ce061606caa7951a05 • android-arm64  • Android 8.0.0
      (API 26)
    • Chrome (web)      • chrome             • web-javascript • Google Chrome
      91.0.4472.164

• No issues found!

@ajaysanity
Copy link

ajaysanity commented Sep 24, 2021

We have the same issue. I fixed it by changing the physicalKey to key

   for (final PhysicalKeyboardKey key in physicalKeysPressed.difference(_rawKeyboard.physicalKeysPressed)) {
      _keyEventsSinceLastMessage.add(KeyUpEvent(
        physicalKey: key,
        logicalKey: _hardwareKeyboard.lookUpLayout(key)!,
        timeStamp: timeStamp,
        synthesized: true,
      ));
    }
    for (final PhysicalKeyboardKey key in _rawKeyboard.physicalKeysPressed.difference(physicalKeysPressed)) {
      _keyEventsSinceLastMessage.add(KeyDownEvent(
        physicalKey: key,
        logicalKey: _rawKeyboard.lookUpLayout(key)!,
        timeStamp: timeStamp,
        synthesized: true,
      ));
    }

@mikeesouth
Copy link

mikeesouth commented Sep 25, 2021

This bug broke my app completely on Chromebooks with physical keyboard when upgrading to Flutter 2.5.0. After upgrading to Flutter 2.5.1 it works much better but right shift and right control on the Chromebook still causes the same exception. I'm not sure why right shift/control throws this exception but left shift and left control works without exception. Other modifiers and special keys like alt, alt gr, tab, esc, media controls, backspace, dash, comma etc. does not cause the bug but right shift and right control does? Very strange.

I can reproduce this with these simple steps:

  1. flutter create buggy_right_shift_chromebook
  2. Add a TextFormField(), e.g. on line 105 under the counter text widget in the example
  3. Start the app, focus the text field, press right shift or right control - boom. Exception thrown.

I reproduced this on flutter stable 2.5.1 and beta channel (2.6.0-5.2.pre) - same result in both cases. I tried master channel too (2.6.0-12.0.pre.89) but same result there. I'm reproducing it on a Chromebook from HP, model "HP Chromebook - 14-db0004no" (link to specs here). The Chromebook runs ChromeOS 96.0.4648.0, 64 bit.

Any ideas on something that I may be missing?

_CastError

════════ Exception caught by services library ══════════════════════════════════
The following _CastError was thrown during a platform message callback:
Null check operator used on a null value

When the exception was thrown, this was the stack
#0 KeyEventManager._convertRawEventAndStore
package:flutter/…/services/hardware_keyboard.dart:884
#1 RawKeyboard.handleRawKeyEvent
package:flutter/…/services/raw_keyboard.dart:677
#2 KeyEventManager.handleRawKeyMessage
package:flutter/…/services/hardware_keyboard.dart:818
#3 BasicMessageChannel.setMessageHandler.
package:flutter/…/services/platform_channel.dart:73
#4 BasicMessageChannel.setMessageHandler.
package:flutter/…/services/platform_channel.dart:72
#5 _DefaultBinaryMessenger.setMessageHandler.
package:flutter/…/services/binding.dart:379
#6 _DefaultBinaryMessenger.setMessageHandler.
package:flutter/…/services/binding.dart:376
#7 _invoke2. (dart:ui/hooks.dart:205:15)
#11 _invoke2 (dart:ui/hooks.dart:204:10)
#12 _ChannelCallbackRecord.invoke (dart:ui/channel_buffers.dart:42:5)

flutter doctor -v

[√] Flutter (Channel stable, 2.5.1, on Microsoft Windows [Version 10.0.19041.1237], locale sv-SE)
• Flutter version 2.5.1 at C:\Stuff\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision ffb2ece (8 days ago), 2021-09-17 15:26:33 -0400
• Engine revision b3af521a05
• Dart version 2.14.2

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
• Android SDK at C:\Users\Micke\AppData\Local\Android\sdk
• Platform android-30, build-tools 30.0.2
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
• All Android licenses accepted.

[√] Chrome - develop for the web
• Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[√] Android Studio (version 2020.3)
• Android Studio at C:\Program Files\Android\Android Studio
• 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 11.0.10+0-b96-7249189)

[√] VS Code (version 1.60.2)
• VS Code at C:\Users\Micke\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.26.0

[√] Connected device (4 available)
• grunt (mobile) • 192.168.86.47:5555 • android-x64 • Android 9 (API 28)
• Android SDK built for x86 (mobile) • emulator-5554 • android-x86 • Android 10 (API 29) (emulator)
• Chrome (web) • chrome • web-javascript • Google Chrome 92.0.4515.159
• Edge (web) • edge • web-javascript • Microsoft Edge 93.0.961.47

• No issues found!

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a: null-safety Support for Dart's null safety feature a: production Issues experienced in live production apps a: text input Entering text in a text field or keyboard related problems c: regression It was better in the past than it is now framework flutter/packages/flutter repository. See also f: labels. platform-android Android applications specifically r: fixed Issue is closed as already fixed in a newer version
Projects
None yet
Development

No branches or pull requests

10 participants