Skip to content

Test Linux's FlView, and that Keyboard state is reset when engine restarts #91345

@dkwingsmt

Description

@dkwingsmt

We could not find a way to unit test the FlView as of 10/5/2021 (97f027), because most of its code can't be run headlessly. We should add a regression test for flutter/engine#28877 with the following step:

App: any app.

Steps:

  1. Run with flutter run -d linux
  2. Press ShiftLeft and hold
  3. Hot restart the app
  • If run mannually, use the mouse to focus the terminal's window, then press R to hot restart. (You can release ShiftLeft now.)
  1. Switch back to the restarted app, press any key.

Expected: the key press is processed normally.

Actual: The app crashes with the following log:

══╡ 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#4bf2a(physicalKey: PhysicalKeyboardKey#700e1(usbHidUsage: "0x000700e1", debugName:
"Shift Left"), logicalKey: LogicalKeyboardKey#00102(keyId: "0x200000102", keyLabel: "Shift Left",
debugName: "Shift Left"), character: null, timeStamp: 542:07:44.112000, synthesized)
'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.
(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.
(package:flutter/src/services/platform_channel.dart:77:49)
#7 BasicMessageChannel.setMessageHandler.
(package:flutter/src/services/platform_channel.dart:76:47)
#8 _DefaultBinaryMessenger.setMessageHandler.
(package:flutter/src/services/binding.dart:386:35)
#9 _DefaultBinaryMessenger.setMessageHandler.
(package:flutter/src/services/binding.dart:383:46)
#10 _invoke2. (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)
════════════════════════════════════════════════════════════════════════════════════════════════════

** (test_app:594560): WARNING **: 23:43:36.514: Unable to retrieve framework response: Message is not valid JSON

Another exception was thrown: 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#4bf2a(physicalKey: PhysicalKeyboardKey#700e1(usbHidUsage: "0x000700e1", debugName:
"Shift Left"), logicalKey: LogicalKeyboardKey#00102(keyId: "0x200000102", keyLabel: "Shift Left", debugName:
"Shift Left"), character: null, timeStamp: 542:07:44.112000, synthesized)

Note: This crash relies on the assertion on KeyEvent here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: desktopRunning on desktopa: tests"flutter test", flutter_test, or one of our testsa: text inputEntering text in a text field or keyboard related problemsengineflutter/engine related. See also e: labels.found in release: 2.5Found to occur in 2.5found in release: 2.6Found to occur in 2.6has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-linuxBuilding on or for Linux specificallyteam-linuxOwned by the Linux platform teamtriaged-linuxTriaged by the Linux platform team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions