flutter-tizen / engine

The Flutter engine
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
6 stars 19 forks source link

Implement the hardware keyboard interface #297

Closed swift-kim closed 2 years ago

swift-kim commented 2 years ago

Closes https://github.com/flutter-tizen/engine/issues/221.

Please read this page for differences between the legacy RawKeyboard API and the new HardwareKeyboard API.

Since the legacy API has not been deprecated yet, a key event must be sent to the framework twice through the conventional platform channel and also the new embedder API (FlutterEngineSendKeyEvent) simultaneously. In our code, it's done by the SendChannelEvent and SendEmbedderEvent methods in the KeyEventChannel class respectively. As commented in the code, the KeyEventChannel class will be renamed and refactored once the old API is fully removed from the framework.

For the implementation, I referred to the desktop embedders (Windows and Linux) code. Since there's no numeric value that represents a "logical key code" on Tizen, I created a direct mapping (kSymbolToLogicalKeyCode) from key symbols (string) to Flutter's logical key codes.

There are also some other changes to code related to the legacy API:

I'll do some more testing in this week. To test this change, you may create an app that contains Focus widgets such as KeyboardListener (new API) and RawKeyboardListener (legacy API) and implement onKey or onKeyEvent.

bbrto21 commented 2 years ago

I got an error message after apply this when testing TextField.

E] [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: 'package:flutter/src/services/hardware_keyboard.dart': Failed assertion: line 792 pos 16: 'false': Should never encounter KeyData when transitMode is rawKeyData.
#0      _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61)
#1      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5)
#2      KeyEventManager.handleKeyData (package:flutter/src/services/hardware_keyboard.dart:792:16)
#3      PlatformDispatcher._keyDataListener.<anonymous closure>.<anonymous closure> (dart:ui/platform_dispatcher.dart:400:41)
#4      _invoke1 (dart:ui/hooks.dart:168:13)
#5      PlatformDispatcher._keyDataListener.<anonymous closure> (dart:ui/platform_dispatcher.dart:398:7)
#6      _invoke2.<anonymous closure> (dart:ui/hooks.dart:190:15)
#7      _rootRun (dart:async/zone.dart:1426:13)
#8      _CustomZone.run (dart:async/zone.dart:1328:19)
#9      _CustomZone.runGuarded (dart:async/zone.dart:1236:7)
#10     _invoke2 (dart:ui/hooks.dart:189:10)
#11     _ChannelCallbackRecord.invoke (dart:ui/channel_buffers.dart:42:5)
#12     _Channel.push (dart:ui/channel_buffers.dart:132:31)
#13     ChannelBuffers.push (dart:ui/channel_buffers.dart:329:17)
#14     PlatformDispatcher._dispatchPlatformMessage (dart:ui/platform_dispatcher.dart:589:22)
#15     _dispatchPlatformMessage (dart:ui/hooks.dart:89:31)
swift-kim commented 2 years ago

@bbrto21 The error seems to be fixed by https://github.com/flutter-tizen/engine/pull/297/commits/dcd66c107c6c332f5c579e426e29d879f034213e. Could you please check again?

bbrto21 commented 2 years ago

@swift-kim Thanks, problem solved!