Unverified Commit 041a3eaa authored by Greg Spencer's avatar Greg Spencer Committed by GitHub

Standardize the nullability of arguments to raw key data constructors. (#63523)

This standardizes the handling of nullability for the LogicalKeyboardKey.keyLabel and RawKeyEventData.keyLabel accessors so that they are non-nullable, but can be empty.

Before this change, the keyLabel could be either null or an empty string to indicate that there wasn't a label, which makes it harder to test for, since both need to be checked for. Since an empty string is sufficient, there is no need for it to be nullable.

Also, in raw_keyboard.dart, the web and Windows implementations wouldn't accept null values for parameters in the Map coming from the message, but tests were supplying null for some of them. This makes web and Windows creation of events match the other platforms, and makes the migration of tests to non-nullability easier.
parent 69fd5c50
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8 import 'package:flutter/foundation.dart';
// DO NOT EDIT -- DO NOT EDIT -- DO NOT EDIT // DO NOT EDIT -- DO NOT EDIT -- DO NOT EDIT
// This file is generated by dev/tools/gen_keycodes/bin/gen_keycodes.dart and // This file is generated by dev/tools/gen_keycodes/bin/gen_keycodes.dart and
...@@ -11,8 +11,6 @@ ...@@ -11,8 +11,6 @@
// Edit the template dev/tools/gen_keycodes/data/keyboard_key.tmpl instead. // Edit the template dev/tools/gen_keycodes/data/keyboard_key.tmpl instead.
// See dev/tools/gen_keycodes/README.md for more information. // See dev/tools/gen_keycodes/README.md for more information.
import 'package:flutter/foundation.dart';
/// A base class for all keyboard key types. /// A base class for all keyboard key types.
/// ///
/// See also: /// See also:
...@@ -138,7 +136,7 @@ class LogicalKeyboardKey extends KeyboardKey { ...@@ -138,7 +136,7 @@ class LogicalKeyboardKey extends KeyboardKey {
/// const LogicalKeyboardKey(0x0010000000a, debugName: kReleaseMode ? null : 'Special Key') /// const LogicalKeyboardKey(0x0010000000a, debugName: kReleaseMode ? null : 'Special Key')
/// ``` /// ```
/// {@end-tool} /// {@end-tool}
const LogicalKeyboardKey(this.keyId, {this.debugName, this.keyLabel}) const LogicalKeyboardKey(this.keyId, {this.debugName, this.keyLabel = ''})
: assert(keyId != null); : assert(keyId != null);
/// A unique code representing this key. /// A unique code representing this key.
...@@ -156,7 +154,7 @@ class LogicalKeyboardKey extends KeyboardKey { ...@@ -156,7 +154,7 @@ class LogicalKeyboardKey extends KeyboardKey {
/// This value is useful for describing or matching mnemonic keyboard /// This value is useful for describing or matching mnemonic keyboard
/// shortcuts. /// shortcuts.
/// ///
/// This value can be null if there's no key label data for a key. /// This value is an empty string if there's no key label data for a key.
/// ///
/// On most platforms this is a single code point, but it could contain any /// On most platforms this is a single code point, but it could contain any
/// Unicode string. The `keyLabel` differs from [RawKeyEvent.character] /// Unicode string. The `keyLabel` differs from [RawKeyEvent.character]
...@@ -166,7 +164,7 @@ class LogicalKeyboardKey extends KeyboardKey { ...@@ -166,7 +164,7 @@ class LogicalKeyboardKey extends KeyboardKey {
/// “o” for [keyLabel], but would return “ö” for [RawKeyEvent.character]. /// “o” for [keyLabel], but would return “ö” for [RawKeyEvent.character].
/// ///
/// {@macro flutter.services.RawKeyEventData.keyLabel} /// {@macro flutter.services.RawKeyEventData.keyLabel}
final String? keyLabel; final String keyLabel;
@override @override
int get hashCode => keyId.hashCode; int get hashCode => keyId.hashCode;
...@@ -194,7 +192,7 @@ class LogicalKeyboardKey extends KeyboardKey { ...@@ -194,7 +192,7 @@ class LogicalKeyboardKey extends KeyboardKey {
/// ///
/// Used by [RawKeyEvent] subclasses to help construct IDs. /// Used by [RawKeyEvent] subclasses to help construct IDs.
static bool isControlCharacter(String label) { static bool isControlCharacter(String label) {
if (label.length > 1) { if (label.length != 1) {
return false; return false;
} }
final int codeUnit = label.codeUnitAt(0); final int codeUnit = label.codeUnitAt(0);
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter/foundation.dart';
// DO NOT EDIT -- DO NOT EDIT -- DO NOT EDIT // DO NOT EDIT -- DO NOT EDIT -- DO NOT EDIT
// This file is generated by dev/tools/gen_keycodes/bin/gen_keycodes.dart and // This file is generated by dev/tools/gen_keycodes/bin/gen_keycodes.dart and
...@@ -10,8 +11,6 @@ ...@@ -10,8 +11,6 @@
// Edit the template dev/tools/gen_keycodes/data/keyboard_key.tmpl instead. // Edit the template dev/tools/gen_keycodes/data/keyboard_key.tmpl instead.
// See dev/tools/gen_keycodes/README.md for more information. // See dev/tools/gen_keycodes/README.md for more information.
import 'package:flutter/foundation.dart';
/// A base class for all keyboard key types. /// A base class for all keyboard key types.
/// ///
/// See also: /// See also:
...@@ -137,7 +136,7 @@ class LogicalKeyboardKey extends KeyboardKey { ...@@ -137,7 +136,7 @@ class LogicalKeyboardKey extends KeyboardKey {
/// const LogicalKeyboardKey(0x0010000000a, debugName: kReleaseMode ? null : 'Special Key') /// const LogicalKeyboardKey(0x0010000000a, debugName: kReleaseMode ? null : 'Special Key')
/// ``` /// ```
/// {@end-tool} /// {@end-tool}
const LogicalKeyboardKey(this.keyId, {this.debugName, this.keyLabel}) const LogicalKeyboardKey(this.keyId, {this.debugName, this.keyLabel = ''})
: assert(keyId != null); : assert(keyId != null);
/// A unique code representing this key. /// A unique code representing this key.
...@@ -155,7 +154,7 @@ class LogicalKeyboardKey extends KeyboardKey { ...@@ -155,7 +154,7 @@ class LogicalKeyboardKey extends KeyboardKey {
/// This value is useful for describing or matching mnemonic keyboard /// This value is useful for describing or matching mnemonic keyboard
/// shortcuts. /// shortcuts.
/// ///
/// This value can be null if there's no key label data for a key. /// This value is an empty string if there's no key label data for a key.
/// ///
/// On most platforms this is a single code point, but it could contain any /// On most platforms this is a single code point, but it could contain any
/// Unicode string. The `keyLabel` differs from [RawKeyEvent.character] /// Unicode string. The `keyLabel` differs from [RawKeyEvent.character]
...@@ -165,7 +164,7 @@ class LogicalKeyboardKey extends KeyboardKey { ...@@ -165,7 +164,7 @@ class LogicalKeyboardKey extends KeyboardKey {
/// “o” for [keyLabel], but would return “ö” for [RawKeyEvent.character]. /// “o” for [keyLabel], but would return “ö” for [RawKeyEvent.character].
/// ///
/// {@macro flutter.services.RawKeyEventData.keyLabel} /// {@macro flutter.services.RawKeyEventData.keyLabel}
final String? keyLabel; final String keyLabel;
@override @override
int get hashCode => keyId.hashCode; int get hashCode => keyId.hashCode;
...@@ -193,7 +192,7 @@ class LogicalKeyboardKey extends KeyboardKey { ...@@ -193,7 +192,7 @@ class LogicalKeyboardKey extends KeyboardKey {
/// ///
/// Used by [RawKeyEvent] subclasses to help construct IDs. /// Used by [RawKeyEvent] subclasses to help construct IDs.
static bool isControlCharacter(String label) { static bool isControlCharacter(String label) {
if (label.length > 1) { if (label.length != 1) {
return false; return false;
} }
final int codeUnit = label.codeUnitAt(0); final int codeUnit = label.codeUnitAt(0);
......
...@@ -213,6 +213,8 @@ abstract class RawKeyEventData { ...@@ -213,6 +213,8 @@ abstract class RawKeyEventData {
/// Returns the Unicode string representing the label on this key. /// Returns the Unicode string representing the label on this key.
/// ///
/// This value is an empty string if there's no key label data for a key.
///
/// {@template flutter.services.RawKeyEventData.keyLabel} /// {@template flutter.services.RawKeyEventData.keyLabel}
/// Do not use the [keyLabel] to compose a text string: it will be missing /// Do not use the [keyLabel] to compose a text string: it will be missing
/// special processing for Unicode strings for combining characters and other /// special processing for Unicode strings for combining characters and other
...@@ -226,7 +228,7 @@ abstract class RawKeyEventData { ...@@ -226,7 +228,7 @@ abstract class RawKeyEventData {
/// complexities of managing keyboard input, like showing a soft keyboard or /// complexities of managing keyboard input, like showing a soft keyboard or
/// interacting with an input method editor (IME). /// interacting with an input method editor (IME).
/// {@endtemplate} /// {@endtemplate}
String? get keyLabel; String get keyLabel;
} }
/// Defines the interface for raw key events. /// Defines the interface for raw key events.
...@@ -308,17 +310,17 @@ abstract class RawKeyEvent with Diagnosticable { ...@@ -308,17 +310,17 @@ abstract class RawKeyEvent with Diagnosticable {
break; break;
case 'web': case 'web':
data = RawKeyEventDataWeb( data = RawKeyEventDataWeb(
code: message['code'] as String, code: message['code'] as String? ?? '',
key: message['key'] as String, key: message['key'] as String? ?? '',
metaState: message['metaState'] as int, metaState: message['metaState'] as int? ?? 0,
); );
break; break;
case 'windows': case 'windows':
data = RawKeyEventDataWindows( data = RawKeyEventDataWindows(
keyCode: message['keyCode'] as int, keyCode: message['keyCode'] as int? ?? 0,
scanCode: message['scanCode'] as int, scanCode: message['scanCode'] as int? ?? 0,
characterCodePoint: message['characterCodePoint'] as int, characterCodePoint: message['characterCodePoint'] as int? ?? 0,
modifiers: message['modifiers'] as int, modifiers: message['modifiers'] as int? ?? 0,
); );
break; break;
default: default:
......
...@@ -147,7 +147,7 @@ class RawKeyEventDataAndroid extends RawKeyEventData { ...@@ -147,7 +147,7 @@ class RawKeyEventDataAndroid extends RawKeyEventData {
// Android only reports a single code point for the key label. // Android only reports a single code point for the key label.
@override @override
String? get keyLabel => plainCodePoint == 0 ? null : String.fromCharCode(plainCodePoint & _kCombiningCharacterMask); String get keyLabel => plainCodePoint == 0 ? '' : String.fromCharCode(plainCodePoint & _kCombiningCharacterMask);
@override @override
PhysicalKeyboardKey get physicalKey { PhysicalKeyboardKey get physicalKey {
...@@ -191,13 +191,13 @@ class RawKeyEventDataAndroid extends RawKeyEventData { ...@@ -191,13 +191,13 @@ class RawKeyEventDataAndroid extends RawKeyEventData {
// constant, or construct a new Unicode-based key from it. Don't mark it as // constant, or construct a new Unicode-based key from it. Don't mark it as
// autogenerated, since the label uniquely identifies an ID from the Unicode // autogenerated, since the label uniquely identifies an ID from the Unicode
// plane. // plane.
if (keyLabel != null && keyLabel!.isNotEmpty && !LogicalKeyboardKey.isControlCharacter(keyLabel!)) { if (keyLabel.isNotEmpty && !LogicalKeyboardKey.isControlCharacter(keyLabel)) {
final int combinedCodePoint = plainCodePoint & _kCombiningCharacterMask; final int combinedCodePoint = plainCodePoint & _kCombiningCharacterMask;
final int keyId = LogicalKeyboardKey.unicodePlane | (combinedCodePoint & LogicalKeyboardKey.valueMask); final int keyId = LogicalKeyboardKey.unicodePlane | (combinedCodePoint & LogicalKeyboardKey.valueMask);
return LogicalKeyboardKey.findKeyByKeyId(keyId) ?? LogicalKeyboardKey( return LogicalKeyboardKey.findKeyByKeyId(keyId) ?? LogicalKeyboardKey(
keyId, keyId,
keyLabel: keyLabel, keyLabel: keyLabel,
debugName: kReleaseMode ? null : 'Key ${keyLabel!.toUpperCase()}', debugName: kReleaseMode ? null : 'Key ${keyLabel.toUpperCase()}',
); );
} }
......
...@@ -61,7 +61,7 @@ class RawKeyEventDataFuchsia extends RawKeyEventData { ...@@ -61,7 +61,7 @@ class RawKeyEventDataFuchsia extends RawKeyEventData {
// Fuchsia only reports a single code point for the key label. // Fuchsia only reports a single code point for the key label.
@override @override
String? get keyLabel => codePoint == 0 ? null : String.fromCharCode(codePoint); String get keyLabel => codePoint == 0 ? '' : String.fromCharCode(codePoint);
@override @override
LogicalKeyboardKey get logicalKey { LogicalKeyboardKey get logicalKey {
......
...@@ -70,7 +70,7 @@ class RawKeyEventDataLinux extends RawKeyEventData { ...@@ -70,7 +70,7 @@ class RawKeyEventDataLinux extends RawKeyEventData {
final bool isDown; final bool isDown;
@override @override
String? get keyLabel => unicodeScalarValues == 0 ? null : String.fromCharCode(unicodeScalarValues); String get keyLabel => unicodeScalarValues == 0 ? '' : String.fromCharCode(unicodeScalarValues);
@override @override
PhysicalKeyboardKey get physicalKey => kLinuxToPhysicalKey[scanCode] ?? PhysicalKeyboardKey.none; PhysicalKeyboardKey get physicalKey => kLinuxToPhysicalKey[scanCode] ?? PhysicalKeyboardKey.none;
...@@ -89,13 +89,13 @@ class RawKeyEventDataLinux extends RawKeyEventData { ...@@ -89,13 +89,13 @@ class RawKeyEventDataLinux extends RawKeyEventData {
// constant, or construct a new Unicode-based key from it. Don't mark it as // constant, or construct a new Unicode-based key from it. Don't mark it as
// autogenerated, since the label uniquely identifies an ID from the Unicode // autogenerated, since the label uniquely identifies an ID from the Unicode
// plane. // plane.
if (keyLabel != null && if (keyLabel.isNotEmpty &&
!LogicalKeyboardKey.isControlCharacter(keyLabel!)) { !LogicalKeyboardKey.isControlCharacter(keyLabel)) {
final int keyId = LogicalKeyboardKey.unicodePlane | (unicodeScalarValues & LogicalKeyboardKey.valueMask); final int keyId = LogicalKeyboardKey.unicodePlane | (unicodeScalarValues & LogicalKeyboardKey.valueMask);
return LogicalKeyboardKey.findKeyByKeyId(keyId) ?? LogicalKeyboardKey( return LogicalKeyboardKey.findKeyByKeyId(keyId) ?? LogicalKeyboardKey(
keyId, keyId,
keyLabel: keyLabel, keyLabel: keyLabel,
debugName: kReleaseMode ? null : 'Key ${keyLabel!.toUpperCase()}', debugName: kReleaseMode ? null : 'Key ${keyLabel.toUpperCase()}',
); );
} }
......
...@@ -62,7 +62,7 @@ class RawKeyEventDataMacOs extends RawKeyEventData { ...@@ -62,7 +62,7 @@ class RawKeyEventDataMacOs extends RawKeyEventData {
final int modifiers; final int modifiers;
@override @override
String? get keyLabel => charactersIgnoringModifiers.isEmpty ? null : charactersIgnoringModifiers; String get keyLabel => charactersIgnoringModifiers;
@override @override
PhysicalKeyboardKey get physicalKey => kMacOsToPhysicalKey[keyCode] ?? PhysicalKeyboardKey.none; PhysicalKeyboardKey get physicalKey => kMacOsToPhysicalKey[keyCode] ?? PhysicalKeyboardKey.none;
...@@ -76,15 +76,17 @@ class RawKeyEventDataMacOs extends RawKeyEventData { ...@@ -76,15 +76,17 @@ class RawKeyEventDataMacOs extends RawKeyEventData {
if (numPadKey != null) { if (numPadKey != null) {
return numPadKey; return numPadKey;
} }
// If this key is printable, generate the LogicalKeyboardKey from its Unicode value. // If this key is printable, generate the LogicalKeyboardKey from its
// Control keys such as ESC, CRTL, and SHIFT are not printable. HOME, DEL, arrow keys, and function // Unicode value. Control keys such as ESC, CRTL, and SHIFT are not
// keys are considered modifier function keys, which generate invalid Unicode scalar values. // printable. HOME, DEL, arrow keys, and function keys are considered
if (keyLabel != null && // modifier function keys, which generate invalid Unicode scalar values.
!LogicalKeyboardKey.isControlCharacter(keyLabel!) && if (keyLabel.isNotEmpty &&
!_isUnprintableKey(keyLabel!)) { !LogicalKeyboardKey.isControlCharacter(keyLabel) &&
// Given that charactersIgnoringModifiers can contain a String of arbitrary length, !_isUnprintableKey(keyLabel)) {
// limit to a maximum of two Unicode scalar values. It is unlikely that a keyboard would produce a code point // Given that charactersIgnoringModifiers can contain a String of
// bigger than 32 bits, but it is still worth defending against this case. // arbitrary length, limit to a maximum of two Unicode scalar values. It
// is unlikely that a keyboard would produce a code point bigger than 32
// bits, but it is still worth defending against this case.
assert(charactersIgnoringModifiers.length <= 2); assert(charactersIgnoringModifiers.length <= 2);
int codeUnit = charactersIgnoringModifiers.codeUnitAt(0); int codeUnit = charactersIgnoringModifiers.codeUnitAt(0);
if (charactersIgnoringModifiers.length == 2) { if (charactersIgnoringModifiers.length == 2) {
...@@ -96,20 +98,21 @@ class RawKeyEventDataMacOs extends RawKeyEventData { ...@@ -96,20 +98,21 @@ class RawKeyEventDataMacOs extends RawKeyEventData {
return LogicalKeyboardKey.findKeyByKeyId(keyId) ?? LogicalKeyboardKey( return LogicalKeyboardKey.findKeyByKeyId(keyId) ?? LogicalKeyboardKey(
keyId, keyId,
keyLabel: keyLabel, keyLabel: keyLabel,
debugName: kReleaseMode ? null : 'Key ${keyLabel!.toUpperCase()}', debugName: kReleaseMode ? null : 'Key ${keyLabel.toUpperCase()}',
); );
} }
// Control keys like "backspace" and movement keys like arrow keys don't have a printable representation, // Control keys like "backspace" and movement keys like arrow keys don't
// but are present on the physical keyboard. Since there is no logical keycode map for macOS // have a printable representation, but are present on the physical
// (macOS uses the keycode to reference physical keys), a LogicalKeyboardKey is created with // keyboard. Since there is no logical keycode map for macOS (macOS uses the
// the physical key's HID usage and debugName. This avoids duplicating the physical // keycode to reference physical keys), a LogicalKeyboardKey is created with
// key map. // the physical key's HID usage and debugName. This avoids duplicating the
// physical key map.
if (physicalKey != PhysicalKeyboardKey.none) { if (physicalKey != PhysicalKeyboardKey.none) {
final int keyId = physicalKey.usbHidUsage | LogicalKeyboardKey.hidPlane; final int keyId = physicalKey.usbHidUsage | LogicalKeyboardKey.hidPlane;
return LogicalKeyboardKey.findKeyByKeyId(keyId) ?? LogicalKeyboardKey( return LogicalKeyboardKey.findKeyByKeyId(keyId) ?? LogicalKeyboardKey(
keyId, keyId,
keyLabel: physicalKey.debugName, keyLabel: physicalKey.debugName ?? '',
debugName: physicalKey.debugName, debugName: physicalKey.debugName,
); );
} }
...@@ -129,10 +132,9 @@ class RawKeyEventDataMacOs extends RawKeyEventData { ...@@ -129,10 +132,9 @@ class RawKeyEventDataMacOs extends RawKeyEventData {
return false; return false;
} }
// If only the "anyMask" bit is set, then we respond true for requests of // If only the "anyMask" bit is set, then we respond true for requests of
// whether either left or right is pressed. // whether either left or right is pressed. Handles the case where macOS
// Handles the case where macOS supplies just the "either" modifier flag, // supplies just the "either" modifier flag, but not the left/right flag.
// but not the left/right flag. (e.g. modifierShift but not // (e.g. modifierShift but not modifierLeftShift).
// modifierLeftShift).
final bool anyOnly = modifiers & (leftMask | rightMask | anyMask) == anyMask; final bool anyOnly = modifiers & (leftMask | rightMask | anyMask) == anyMask;
switch (side) { switch (side) {
case KeyboardSide.any: case KeyboardSide.any:
...@@ -229,7 +231,7 @@ class RawKeyEventDataMacOs extends RawKeyEventData { ...@@ -229,7 +231,7 @@ class RawKeyEventDataMacOs extends RawKeyEventData {
/// ///
/// Used by [RawKeyEvent] subclasses to help construct IDs. /// Used by [RawKeyEvent] subclasses to help construct IDs.
static bool _isUnprintableKey(String label) { static bool _isUnprintableKey(String label) {
if (label.length > 1) { if (label.length != 1) {
return false; return false;
} }
final int codeUnit = label.codeUnitAt(0); final int codeUnit = label.codeUnitAt(0);
......
...@@ -36,7 +36,7 @@ class RawKeyEventDataWeb extends RawKeyEventData { ...@@ -36,7 +36,7 @@ class RawKeyEventDataWeb extends RawKeyEventData {
/// ///
/// See <https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key> /// See <https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key>
/// for more information. /// for more information.
final String? key; final String key;
/// The modifiers that were present when the key event occurred. /// The modifiers that were present when the key event occurred.
/// ///
...@@ -56,7 +56,7 @@ class RawKeyEventDataWeb extends RawKeyEventData { ...@@ -56,7 +56,7 @@ class RawKeyEventDataWeb extends RawKeyEventData {
final int metaState; final int metaState;
@override @override
String? get keyLabel => key; String get keyLabel => key == 'Unidentified' ? '' : key;
@override @override
PhysicalKeyboardKey get physicalKey { PhysicalKeyboardKey get physicalKey {
......
...@@ -54,7 +54,7 @@ class RawKeyEventDataWindows extends RawKeyEventData { ...@@ -54,7 +54,7 @@ class RawKeyEventDataWindows extends RawKeyEventData {
final int modifiers; final int modifiers;
@override @override
String? get keyLabel => characterCodePoint == 0 ? null : String.fromCharCode(characterCodePoint); String get keyLabel => characterCodePoint == 0 ? '' : String.fromCharCode(characterCodePoint);
@override @override
PhysicalKeyboardKey get physicalKey => kWindowsToPhysicalKey[scanCode] ?? PhysicalKeyboardKey.none; PhysicalKeyboardKey get physicalKey => kWindowsToPhysicalKey[scanCode] ?? PhysicalKeyboardKey.none;
...@@ -73,12 +73,12 @@ class RawKeyEventDataWindows extends RawKeyEventData { ...@@ -73,12 +73,12 @@ class RawKeyEventDataWindows extends RawKeyEventData {
// constant, or construct a new Unicode-based key from it. Don't mark it as // constant, or construct a new Unicode-based key from it. Don't mark it as
// autogenerated, since the label uniquely identifies an ID from the Unicode // autogenerated, since the label uniquely identifies an ID from the Unicode
// plane. // plane.
if (keyLabel != null && keyLabel!.isNotEmpty && !LogicalKeyboardKey.isControlCharacter(keyLabel!)) { if (keyLabel.isNotEmpty && !LogicalKeyboardKey.isControlCharacter(keyLabel)) {
final int keyId = LogicalKeyboardKey.unicodePlane | (characterCodePoint & LogicalKeyboardKey.valueMask); final int keyId = LogicalKeyboardKey.unicodePlane | (characterCodePoint & LogicalKeyboardKey.valueMask);
return LogicalKeyboardKey.findKeyByKeyId(keyId) ?? LogicalKeyboardKey( return LogicalKeyboardKey.findKeyByKeyId(keyId) ?? LogicalKeyboardKey(
keyId, keyId,
keyLabel: keyLabel, keyLabel: keyLabel,
debugName: kReleaseMode ? null : 'Key ${keyLabel!.toUpperCase()}', debugName: kReleaseMode ? null : 'Key ${keyLabel.toUpperCase()}',
); );
} }
// Look to see if the keyCode is one we know about and have a mapping for. // Look to see if the keyCode is one we know about and have a mapping for.
...@@ -104,10 +104,9 @@ class RawKeyEventDataWindows extends RawKeyEventData { ...@@ -104,10 +104,9 @@ class RawKeyEventDataWindows extends RawKeyEventData {
return false; return false;
} }
// If only the "anyMask" bit is set, then we respond true for requests of // If only the "anyMask" bit is set, then we respond true for requests of
// whether either left or right is pressed. // whether either left or right is pressed. Handles the case where Windows
// Handles the case where Windows supplies just the "either" modifier flag, // supplies just the "either" modifier flag, but not the left/right flag.
// but not the left/right flag. (e.g. modifierShift but not // (e.g. modifierShift but not modifierLeftShift).
// modifierLeftShift).
final bool anyOnly = modifiers & (leftMask | rightMask | anyMask) == anyMask; final bool anyOnly = modifiers & (leftMask | rightMask | anyMask) == anyMask;
switch (side) { switch (side) {
case KeyboardSide.any: case KeyboardSide.any:
......
...@@ -180,13 +180,17 @@ class KeyEventSimulator { ...@@ -180,13 +180,17 @@ class KeyEventSimulator {
switch (platform) { switch (platform) {
case 'android': case 'android':
result['keyCode'] = keyCode; result['keyCode'] = keyCode;
result['codePoint'] = key.keyLabel?.codeUnitAt(0); if (key.keyLabel.isNotEmpty) {
result['codePoint'] = key.keyLabel.codeUnitAt(0);
}
result['scanCode'] = scanCode; result['scanCode'] = scanCode;
result['metaState'] = _getAndroidModifierFlags(key, isDown); result['metaState'] = _getAndroidModifierFlags(key, isDown);
break; break;
case 'fuchsia': case 'fuchsia':
result['hidUsage'] = physicalKey?.usbHidUsage ?? (key.keyId & LogicalKeyboardKey.hidPlane != 0 ? key.keyId & LogicalKeyboardKey.valueMask : null); result['hidUsage'] = physicalKey?.usbHidUsage ?? (key.keyId & LogicalKeyboardKey.hidPlane != 0 ? key.keyId & LogicalKeyboardKey.valueMask : null);
result['codePoint'] = key.keyLabel?.codeUnitAt(0); if (key.keyLabel.isNotEmpty) {
result['codePoint'] = key.keyLabel.codeUnitAt(0);
}
result['modifiers'] = _getFuchsiaModifierFlags(key, isDown); result['modifiers'] = _getFuchsiaModifierFlags(key, isDown);
break; break;
case 'linux': case 'linux':
...@@ -209,7 +213,9 @@ class KeyEventSimulator { ...@@ -209,7 +213,9 @@ class KeyEventSimulator {
case 'windows': case 'windows':
result['keyCode'] = keyCode; result['keyCode'] = keyCode;
result['scanCode'] = scanCode; result['scanCode'] = scanCode;
result['characterCodePoint'] = key.keyLabel?.codeUnitAt(0) ?? 0; if (key.keyLabel.isNotEmpty) {
result['characterCodePoint'] = key.keyLabel.codeUnitAt(0);
}
result['modifiers'] = _getWindowsModifierFlags(key, isDown); result['modifiers'] = _getWindowsModifierFlags(key, isDown);
} }
return result; return result;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment