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

@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/foundation.dart';
// DO NOT EDIT -- DO NOT EDIT -- DO NOT EDIT
// This file is generated by dev/tools/gen_keycodes/bin/gen_keycodes.dart and
@@ -11,8 +11,6 @@
// Edit the template dev/tools/gen_keycodes/data/keyboard_key.tmpl instead.
// See dev/tools/gen_keycodes/README.md for more information.
import 'package:flutter/foundation.dart';
/// A base class for all keyboard key types.
///
/// See also:
@@ -138,7 +136,7 @@ class LogicalKeyboardKey extends KeyboardKey {
/// const LogicalKeyboardKey(0x0010000000a, debugName: kReleaseMode ? null : 'Special Key')
/// ```
/// {@end-tool}
const LogicalKeyboardKey(this.keyId, {this.debugName, this.keyLabel})
const LogicalKeyboardKey(this.keyId, {this.debugName, this.keyLabel = ''})
: assert(keyId != null);
/// A unique code representing this key.
@@ -156,7 +154,7 @@ class LogicalKeyboardKey extends KeyboardKey {
/// This value is useful for describing or matching mnemonic keyboard
/// 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
/// Unicode string. The `keyLabel` differs from [RawKeyEvent.character]
@@ -166,7 +164,7 @@ class LogicalKeyboardKey extends KeyboardKey {
/// “o” for [keyLabel], but would return “ö” for [RawKeyEvent.character].
///
/// {@macro flutter.services.RawKeyEventData.keyLabel}
final String? keyLabel;
final String keyLabel;
@override
int get hashCode => keyId.hashCode;
@@ -194,7 +192,7 @@ class LogicalKeyboardKey extends KeyboardKey {
///
/// Used by [RawKeyEvent] subclasses to help construct IDs.
static bool isControlCharacter(String label) {
if (label.length > 1) {
if (label.length != 1) {
return false;
}
final int codeUnit = label.codeUnitAt(0);