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.
This commit is contained in:
Greg Spencer
2020-08-19 15:03:17 -07:00
committed by GitHub
parent 69fd5c50a2
commit 041a3eaa84
11 changed files with 89 additions and 101 deletions

View File

@@ -180,13 +180,17 @@ class KeyEventSimulator {
switch (platform) {
case 'android':
result['keyCode'] = keyCode;
result['codePoint'] = key.keyLabel?.codeUnitAt(0);
if (key.keyLabel.isNotEmpty) {
result['codePoint'] = key.keyLabel.codeUnitAt(0);
}
result['scanCode'] = scanCode;
result['metaState'] = _getAndroidModifierFlags(key, isDown);
break;
case 'fuchsia':
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);
break;
case 'linux':
@@ -209,7 +213,9 @@ class KeyEventSimulator {
case 'windows':
result['keyCode'] = keyCode;
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);
}
return result;