Unverified Commit a33dec1a authored by Greg Spencer's avatar Greg Spencer Committed by GitHub

Deprecate `RawKeyEvent`, `RawKeyboard`, et al. (#136677)

## Description

This starts the deprecation of the `RawKeyEvent`/`RawKeyboard` event system that has been replaced by the `KeyEvent`/`HardwareKeyboard` event system.

Migration guide is available here: https://docs.flutter.dev/release/breaking-changes/key-event-migration

## Related Issues
 - https://github.com/flutter/flutter/issues/136419

## Related PRs
 - https://github.com/flutter/website/pull/9889
parent 97190973
......@@ -5,6 +5,10 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
// TODO(gspencergoog): Delete this example when deprecated RawKeyEvent API is
// removed.
// ignore_for_file: deprecated_member_use
/// Flutter code sample for [KeyEventManager.keyMessageHandler].
void main() {
......
......@@ -16,6 +16,7 @@ import 'debug.dart';
import 'hardware_keyboard.dart';
import 'message_codec.dart';
import 'platform_channel.dart';
import 'raw_keyboard.dart' show RawKeyboard;
import 'restoration.dart';
import 'service_extensions.dart';
import 'system_channels.dart';
......@@ -66,6 +67,13 @@ mixin ServicesBinding on BindingBase, SchedulerBinding {
/// The global singleton instance of [KeyEventManager], which is used
/// internally to dispatch key messages.
///
/// This property is deprecated, and will be removed. See
/// [HardwareKeyboard.addHandler] instead.
@Deprecated(
'No longer supported. Add a handler to HardwareKeyboard instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
KeyEventManager get keyEventManager => _keyEventManager;
late final KeyEventManager _keyEventManager;
......@@ -89,8 +97,8 @@ mixin ServicesBinding on BindingBase, SchedulerBinding {
BinaryMessenger get defaultBinaryMessenger => _defaultBinaryMessenger;
late final BinaryMessenger _defaultBinaryMessenger;
/// A token that represents the root isolate, used for coordinating with background
/// isolates.
/// A token that represents the root isolate, used for coordinating with
/// background isolates.
///
/// This property is primarily intended for use with
/// [BackgroundIsolateBinaryMessenger.ensureInitialized], which takes a
......
......@@ -13,6 +13,12 @@ export 'hardware_keyboard.dart' show KeyDataTransitMode;
/// Setting [debugKeyEventSimulatorTransitModeOverride] is a good way to make
/// certain tests simulate the behavior of different type of platforms in terms
/// of their extent of support for keyboard API.
///
/// This value is deprecated and will be removed.
@Deprecated(
'No longer supported. Transit mode is always key data only. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
KeyDataTransitMode? debugKeyEventSimulatorTransitModeOverride;
/// Setting to true will cause extensive logging to occur when key events are
......
......@@ -10,7 +10,6 @@ import 'raw_keyboard.dart';
export 'package:flutter/foundation.dart' show DiagnosticPropertiesBuilder;
export 'keyboard_key.g.dart' show LogicalKeyboardKey, PhysicalKeyboardKey;
export 'raw_keyboard.dart' show KeyboardSide, ModifierKey;
// Android sets the 0x80000000 bit on a character to indicate that it is a
// combining character, so we use this mask to remove that bit to make it a
......@@ -19,14 +18,25 @@ const int _kCombiningCharacterMask = 0x7fffffff;
/// Platform-specific key event data for Android.
///
/// This class is deprecated and will be removed. Platform specific key event
/// data will no longer be available. See [KeyEvent] for what is available.
///
/// This object contains information about key events obtained from Android's
/// `KeyEvent` interface.
///
/// See also:
///
/// * [RawKeyboard], which uses this interface to expose key data.
/// * [RawKeyboard], which uses this interface to expose key data.
@Deprecated(
'Platform specific key event data is no longer available. See KeyEvent for what is available. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
class RawKeyEventDataAndroid extends RawKeyEventData {
/// Creates a key event data structure specific for Android.
@Deprecated(
'Platform specific key event data is no longer available. See KeyEvent for what is available. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
const RawKeyEventDataAndroid({
this.flags = 0,
this.codePoint = 0,
......
......@@ -10,18 +10,28 @@ import 'raw_keyboard.dart';
export 'package:flutter/foundation.dart' show DiagnosticPropertiesBuilder;
export 'keyboard_key.g.dart' show LogicalKeyboardKey, PhysicalKeyboardKey;
export 'raw_keyboard.dart' show KeyboardSide, ModifierKey;
/// Platform-specific key event data for Fuchsia.
///
/// This class is deprecated and will be removed. Platform specific key event
/// data will no longer be available. See [KeyEvent] for what is available.
///
/// This object contains information about key events obtained from Fuchsia's
/// `KeyData` interface.
///
/// See also:
///
/// * [RawKeyboard], which uses this interface to expose key data.
/// * [RawKeyboard], which uses this interface to expose key data.
@Deprecated(
'Platform specific key event data is no longer available. See KeyEvent for what is available. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
class RawKeyEventDataFuchsia extends RawKeyEventData {
/// Creates a key event data structure specific for Fuchsia.
@Deprecated(
'Platform specific key event data is no longer available. See KeyEvent for what is available. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
const RawKeyEventDataFuchsia({
this.hidUsage = 0,
this.codePoint = 0,
......
......@@ -10,18 +10,28 @@ import 'raw_keyboard.dart';
export 'package:flutter/foundation.dart' show DiagnosticPropertiesBuilder;
export 'keyboard_key.g.dart' show LogicalKeyboardKey, PhysicalKeyboardKey;
export 'raw_keyboard.dart' show KeyboardSide, ModifierKey;
/// Platform-specific key event data for iOS.
///
/// This class is deprecated and will be removed. Platform specific key event
/// data will no longer be available. See [KeyEvent] for what is available.
///
/// This object contains information about key events obtained from iOS'
/// `UIKey` interface.
///
/// See also:
///
/// * [RawKeyboard], which uses this interface to expose key data.
@Deprecated(
'Platform specific key event data is no longer available. See KeyEvent for what is available. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
class RawKeyEventDataIos extends RawKeyEventData {
/// Creates a key event data structure specific for iOS.
@Deprecated(
'Platform specific key event data is no longer available. See KeyEvent for what is available. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
const RawKeyEventDataIos({
this.characters = '',
this.charactersIgnoringModifiers = '',
......
......@@ -10,18 +10,28 @@ import 'raw_keyboard.dart';
export 'package:flutter/foundation.dart' show DiagnosticPropertiesBuilder;
export 'keyboard_key.g.dart' show LogicalKeyboardKey, PhysicalKeyboardKey;
export 'raw_keyboard.dart' show KeyboardSide, ModifierKey;
/// Platform-specific key event data for Linux.
///
/// This class is deprecated and will be removed. Platform specific key event
/// data will no longer be available. See [KeyEvent] for what is available.
///
/// Different window toolkit implementations can map to different key codes. This class
/// will use the correct mapping depending on the [keyHelper] provided.
///
/// See also:
///
/// * [RawKeyboard], which uses this interface to expose key data.
@Deprecated(
'Platform specific key event data is no longer available. See KeyEvent for what is available. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
class RawKeyEventDataLinux extends RawKeyEventData {
/// Creates a key event data structure specific for Linux.
@Deprecated(
'Platform specific key event data is no longer available. See KeyEvent for what is available. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
const RawKeyEventDataLinux({
required this.keyHelper,
this.unicodeScalarValues = 0,
......@@ -170,8 +180,19 @@ class RawKeyEventDataLinux extends RawKeyEventData {
/// Given that there might be multiple window toolkit implementations (GLFW,
/// GTK, QT, etc), this creates a common interface for each of the
/// different toolkits.
///
/// This class is deprecated and will be removed. Platform specific key event
/// data will no longer be available. See [KeyEvent] for what is available.
@Deprecated(
'No longer supported. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
abstract class KeyHelper {
/// Create a KeyHelper implementation depending on the given toolkit.
@Deprecated(
'No longer supported. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
factory KeyHelper(String toolkit) {
if (toolkit == 'glfw') {
return GLFWKeyHelper();
......@@ -189,10 +210,18 @@ abstract class KeyHelper {
/// Returns a [KeyboardSide] enum value that describes which side or sides of
/// the given keyboard modifier key were pressed at the time of this event.
@Deprecated(
'No longer supported. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
KeyboardSide getModifierSide(ModifierKey key);
/// Returns true if the given [ModifierKey] was pressed at the time of this
/// event.
@Deprecated(
'No longer supported. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
bool isModifierPressed(ModifierKey key, int modifiers, {KeyboardSide side = KeyboardSide.any, required int keyCode, required bool isDown});
/// The numpad key from the specific key code mapping.
......@@ -206,6 +235,13 @@ abstract class KeyHelper {
}
/// Helper class that uses GLFW-specific key mappings.
///
/// This class is deprecated and will be removed. Platform specific key event
/// data will no longer be available. See [KeyEvent] for what is available.
@Deprecated(
'No longer supported. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
class GLFWKeyHelper implements KeyHelper {
/// This mask is used to check the [RawKeyEventDataLinux.modifiers] field to
/// test whether the CAPS LOCK modifier key is on.
......@@ -343,6 +379,13 @@ class GLFWKeyHelper implements KeyHelper {
}
/// Helper class that uses GTK-specific key mappings.
///
/// This class is deprecated and will be removed. Platform specific key event
/// data will no longer be available. See [KeyEvent] for what is available.
@Deprecated(
'No longer supported. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
class GtkKeyHelper implements KeyHelper {
/// This mask is used to check the [RawKeyEventDataLinux.modifiers] field to
/// test whether one of the SHIFT modifier keys is pressed.
......
......@@ -10,7 +10,6 @@ import 'raw_keyboard.dart';
export 'package:flutter/foundation.dart' show DiagnosticPropertiesBuilder;
export 'keyboard_key.g.dart' show LogicalKeyboardKey, PhysicalKeyboardKey;
export 'raw_keyboard.dart' show KeyboardSide, ModifierKey;
/// Convert a UTF32 rune to its lower case.
int runeToLowerCase(int rune) {
......@@ -25,14 +24,25 @@ int runeToLowerCase(int rune) {
/// Platform-specific key event data for macOS.
///
/// This class is deprecated and will be removed. Platform specific key event
/// data will no longer be available. See [KeyEvent] for what is available.
///
/// This object contains information about key events obtained from macOS's
/// `NSEvent` interface.
///
/// See also:
///
/// * [RawKeyboard], which uses this interface to expose key data.
@Deprecated(
'Platform specific key event data is no longer available. See KeyEvent for what is available. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
class RawKeyEventDataMacOs extends RawKeyEventData {
/// Creates a key event data structure specific for macOS.
@Deprecated(
'Platform specific key event data is no longer available. See KeyEvent for what is available. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
const RawKeyEventDataMacOs({
this.characters = '',
this.charactersIgnoringModifiers = '',
......
......@@ -10,7 +10,6 @@ import 'raw_keyboard.dart';
export 'package:flutter/foundation.dart' show DiagnosticPropertiesBuilder;
export 'keyboard_key.g.dart' show LogicalKeyboardKey, PhysicalKeyboardKey;
export 'raw_keyboard.dart' show KeyboardSide, ModifierKey;
String? _unicodeChar(String key) {
if (key.length == 1) {
......@@ -21,12 +20,23 @@ String? _unicodeChar(String key) {
/// Platform-specific key event data for Web.
///
/// This class is DEPRECATED. Platform specific key event data will no longer
/// available. See [KeyEvent] for what is available.
///
/// See also:
///
/// * [RawKeyboard], which uses this interface to expose key data.
@Deprecated(
'Platform specific key event data is no longer available. See KeyEvent for what is available. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
@immutable
class RawKeyEventDataWeb extends RawKeyEventData {
/// Creates a key event data structure specific for Web.
@Deprecated(
'Platform specific key event data is no longer available. See KeyEvent for what is available. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
const RawKeyEventDataWeb({
required this.code,
required this.key,
......
......@@ -10,7 +10,6 @@ import 'raw_keyboard.dart';
export 'package:flutter/foundation.dart' show DiagnosticPropertiesBuilder;
export 'keyboard_key.g.dart' show LogicalKeyboardKey, PhysicalKeyboardKey;
export 'raw_keyboard.dart' show KeyboardSide, ModifierKey;
// Virtual key VK_PROCESSKEY in Win32 API.
//
......@@ -19,14 +18,25 @@ const int _vkProcessKey = 0xe5;
/// Platform-specific key event data for Windows.
///
/// This class is DEPRECATED. Platform specific key event data will no longer
/// available. See [KeyEvent] for what is available.
///
/// This object contains information about key events obtained from Windows's
/// win32 API.
///
/// See also:
///
/// * [RawKeyboard], which uses this interface to expose key data.
@Deprecated(
'Platform specific key event data is no longer available. See KeyEvent for what is available. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
class RawKeyEventDataWindows extends RawKeyEventData {
/// Creates a key event data structure specific for Windows.
@Deprecated(
'Platform specific key event data is no longer available. See KeyEvent for what is available. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
const RawKeyEventDataWindows({
this.keyCode = 0,
this.scanCode = 0,
......
......@@ -103,10 +103,17 @@ KeyEventResult combineKeyEventResults(Iterable<KeyEventResult> results) {
/// Signature of a callback used by [Focus.onKey] and [FocusScope.onKey]
/// to receive key events.
///
/// This kind of callback is deprecated and will be removed at a future date.
/// Use [FocusOnKeyEventCallback] and associated APIs instead.
///
/// The [node] is the node that received the event.
///
/// Returns a [KeyEventResult] that describes how, and whether, the key event
/// was handled.
@Deprecated(
'Use FocusOnKeyEventCallback instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
typedef FocusOnKeyCallback = KeyEventResult Function(FocusNode node, RawKeyEvent event);
/// Signature of a callback used by [Focus.onKeyEvent] and [FocusScope.onKeyEvent]
......@@ -369,14 +376,13 @@ enum UnfocusDisposition {
/// {@template flutter.widgets.FocusNode.keyEvents}
/// ## Key Event Propagation
///
/// The [FocusManager] receives key events from [RawKeyboard] and
/// [HardwareKeyboard] and will pass them to the focused nodes. It starts with
/// the node with the primary focus, and will call the [onKey] or [onKeyEvent]
/// callback for that node. If the callback returns [KeyEventResult.ignored],
/// indicating that it did not handle the event, the [FocusManager] will move
/// to the parent of that node and call its [onKey] or [onKeyEvent]. If that
/// [onKey] or [onKeyEvent] returns [KeyEventResult.handled], then it will stop
/// propagating the event. If it reaches the root [FocusScopeNode],
/// The [FocusManager] receives key events from [HardwareKeyboard] and will pass
/// them to the focused nodes. It starts with the node with the primary focus,
/// and will call the [onKeyEvent] callback for that node. If the callback
/// returns [KeyEventResult.ignored], indicating that it did not handle the
/// event, the [FocusManager] will move to the parent of that node and call its
/// [onKeyEvent]. If that [onKeyEvent] returns [KeyEventResult.handled], then it
/// will stop propagating the event. If it reaches the root [FocusScopeNode],
/// [FocusManager.rootScope], the event is discarded.
/// {@endtemplate}
///
......@@ -429,11 +435,14 @@ class FocusNode with DiagnosticableTreeMixin, ChangeNotifier {
///
/// The [debugLabel] is ignored on release builds.
///
/// To receive key events that focuses on this node, pass a listener to `onKeyEvent`.
/// The `onKey` is a legacy API based on [RawKeyEvent] and will be deprecated
/// in the future.
/// To receive key events that focuses on this node, pass a listener to
/// `onKeyEvent`.
FocusNode({
String? debugLabel,
@Deprecated(
'Use onKeyEvent instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
this.onKey,
this.onKeyEvent,
bool skipTraversal = false,
......@@ -621,10 +630,17 @@ class FocusNode with DiagnosticableTreeMixin, ChangeNotifier {
/// Called if this focus node receives a key event while focused (i.e. when
/// [hasFocus] returns true).
///
/// This property is deprecated and will be removed at a future date. Use
/// [onKeyEvent] instead.
///
/// This is a legacy API based on [RawKeyEvent] and will be deprecated in the
/// future. Prefer [onKeyEvent] instead.
///
/// {@macro flutter.widgets.FocusNode.keyEvents}
@Deprecated(
'Use onKeyEvent instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
FocusOnKeyCallback? onKey;
/// Called if this focus node receives a key event while focused (i.e. when
......@@ -1035,13 +1051,16 @@ class FocusNode with DiagnosticableTreeMixin, ChangeNotifier {
/// node, and then [attach] called on the new node. This typically happens in
/// the [State.didUpdateWidget] method.
///
/// To receive key events that focuses on this node, pass a listener to `onKeyEvent`.
/// The `onKey` is a legacy API based on [RawKeyEvent] and will be deprecated
/// in the future.
/// To receive key events that focuses on this node, pass a listener to
/// `onKeyEvent`.
@mustCallSuper
FocusAttachment attach(
BuildContext? context, {
FocusOnKeyEventCallback? onKeyEvent,
@Deprecated(
'Use onKeyEvent instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
FocusOnKeyCallback? onKey,
}) {
_context = context;
......@@ -1241,6 +1260,10 @@ class FocusScopeNode extends FocusNode {
FocusScopeNode({
super.debugLabel,
super.onKeyEvent,
@Deprecated(
'Use onKeyEvent instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
super.onKey,
super.skipTraversal,
super.canRequestFocus,
......@@ -1432,8 +1455,8 @@ enum FocusHighlightStrategy {
/// The focus manager is responsible for tracking which [FocusNode] has the
/// primary input focus (the [primaryFocus]), holding the [FocusScopeNode] that
/// is the root of the focus tree (the [rootScope]), and what the current
/// [highlightMode] is. It also distributes key events from [KeyEventManager]
/// to the nodes in the focus tree.
/// [highlightMode] is. It also distributes [KeyEvent]s to the nodes in the
/// focus tree.
///
/// The singleton [FocusManager] instance is held by the [WidgetsBinding] as
/// [WidgetsBinding.focusManager], and can be conveniently accessed using the
......@@ -1490,10 +1513,10 @@ class FocusManager with DiagnosticableTreeMixin, ChangeNotifier {
/// Registers global input event handlers that are needed to manage focus.
///
/// This sets the [RawKeyboard.keyEventHandler] for the shared instance of
/// [RawKeyboard] and adds a route to the global entry in the gesture routing
/// table. As such, only one [FocusManager] instance should register its
/// global handlers.
/// This calls the [HardwareKeyboard.addHandler] on the shared instance of
/// [HardwareKeyboard] and adds a route to the global entry in the gesture
/// routing table. As such, only one [FocusManager] instance should register
/// its global handlers.
///
/// When this focus manager is no longer needed, calling [dispose] on it will
/// unregister these handlers.
......@@ -1856,6 +1879,9 @@ class _HighlightModeManager {
void registerGlobalHandlers() {
assert(ServicesBinding.instance.keyEventManager.keyMessageHandler == null);
// TODO(gspencergoog): Remove this when the RawKeyEvent system is
// deprecated, and replace it with registering a handler on the
// HardwareKeyboard.
ServicesBinding.instance.keyEventManager.keyMessageHandler = handleKeyMessage;
GestureBinding.instance.pointerRouter.addGlobalRoute(handlePointerEvent);
}
......@@ -1964,8 +1990,8 @@ class _HighlightModeManager {
}
// Walk the current focus from the leaf to the root, calling each node's
// onKey on the way up, and if one responds that they handled it or want to
// stop propagation, stop.
// onKeyEvent on the way up, and if one responds that they handled it or
// want to stop propagation, stop.
for (final FocusNode node in <FocusNode>[
FocusManager.instance.primaryFocus!,
...FocusManager.instance.primaryFocus!.ancestors,
......
......@@ -119,6 +119,10 @@ class Focus extends StatefulWidget {
this.autofocus = false,
this.onFocusChange,
FocusOnKeyEventCallback? onKeyEvent,
@Deprecated(
'Use onKeyEvent instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
FocusOnKeyCallback? onKey,
bool? canRequestFocus,
bool? skipTraversal,
......@@ -228,8 +232,7 @@ class Focus extends StatefulWidget {
/// A handler for keys that are pressed when this object or one of its
/// children has focus.
///
/// This is a legacy API based on [RawKeyEvent] and will be deprecated in the
/// future. Prefer [onKeyEvent] instead.
/// This property is deprecated and will be removed. Use [onKeyEvent] instead.
///
/// Key events are first given to the [FocusNode] that has primary focus, and
/// if its [onKey] method return false, then they are given to each ancestor
......@@ -241,6 +244,10 @@ class Focus extends StatefulWidget {
/// keyboards in general. For text input, consider [TextField],
/// [EditableText], or [CupertinoTextField] instead, which do support these
/// things.
@Deprecated(
'Use onKeyEvent instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
FocusOnKeyCallback? get onKey => _onKey ?? focusNode?.onKey;
final FocusOnKeyCallback? _onKey;
......
......@@ -21,16 +21,10 @@ export 'package:flutter/services.dart' show KeyEvent;
/// For text entry, consider using a [EditableText], which integrates with
/// on-screen keyboards and input method editors (IMEs).
///
/// The [KeyboardListener] is different from [RawKeyboardListener] in that
/// [KeyboardListener] uses the newer [HardwareKeyboard] API, which is
/// preferable.
///
/// See also:
///
/// * [EditableText], which should be used instead of this widget for text
/// entry.
/// * [RawKeyboardListener], a similar widget based on the old [RawKeyboard]
/// API.
class KeyboardListener extends StatelessWidget {
/// Creates a widget that receives keyboard events.
///
......
......@@ -14,6 +14,9 @@ export 'package:flutter/services.dart' show RawKeyEvent;
/// A widget that calls a callback whenever the user presses or releases a key
/// on a keyboard.
///
/// The [RawKeyboardListener] is deprecated and will be removed. Use
/// [KeyboardListener] instead.
///
/// A [RawKeyboardListener] is useful for listening to raw key events and
/// hardware buttons that are represented as keys. Typically used by games and
/// other apps that use keyboards for purposes other than text entry.
......@@ -21,21 +24,25 @@ export 'package:flutter/services.dart' show RawKeyEvent;
/// For text entry, consider using a [EditableText], which integrates with
/// on-screen keyboards and input method editors (IMEs).
///
/// The [RawKeyboardListener] is different from [KeyboardListener] in that
/// [RawKeyboardListener] uses the legacy [RawKeyboard] API. Use
/// [KeyboardListener] if possible.
///
/// See also:
///
/// * [EditableText], which should be used instead of this widget for text
/// entry.
/// * [KeyboardListener], a similar widget based on the newer
/// [HardwareKeyboard] API.
/// * [KeyboardListener], a similar widget based on the newer [HardwareKeyboard]
/// API.
@Deprecated(
'Use KeyboardListener instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
class RawKeyboardListener extends StatefulWidget {
/// Creates a widget that receives raw keyboard events.
///
/// For text entry, consider using a [EditableText], which integrates with
/// on-screen keyboards and input method editors (IMEs).
@Deprecated(
'Use KeyboardListener instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
const RawKeyboardListener({
super.key,
required this.focusNode,
......
......@@ -508,9 +508,9 @@ class SingleActivator with Diagnosticable, MenuSerializableShortcut implements S
/// Whether this activator accepts repeat events of the [trigger] key.
///
/// If [includeRepeats] is true, the activator is checked on all
/// [RawKeyDownEvent] events for the [trigger] key. If [includeRepeats] is
/// false, only [trigger] key events which are not [KeyRepeatEvent]s will be
/// considered.
/// [KeyDownEvent] or [KeyRepeatEvent]s for the [trigger] key. If
/// [includeRepeats] is false, only [trigger] key events which are
/// [KeyDownEvent]s will be considered.
final bool includeRepeats;
@override
......@@ -601,10 +601,10 @@ class SingleActivator with Diagnosticable, MenuSerializableShortcut implements S
/// Shift keys are pressed or not, as long as the key event produces the
/// correct character.
///
/// By default, the activator is checked on all [RawKeyDownEvent] events for
/// the [character] in combination with the requested modifier keys. If
/// `includeRepeats` is false, only the [character] events with a false
/// [RawKeyDownEvent.repeat] attribute will be considered.
/// By default, the activator is checked on all [KeyDownEvent] or
/// [KeyRepeatEvent]s for the [character] in combination with the requested
/// modifier keys. If `includeRepeats` is false, only the [character] events
/// with that are [KeyDownEvent]s will be considered.
///
/// {@template flutter.widgets.shortcuts.CharacterActivator.alt}
/// On macOS and iOS, the [alt] flag indicates that the Option key (⌥) is
......@@ -679,9 +679,9 @@ class CharacterActivator with Diagnosticable, MenuSerializableShortcut implement
/// Whether this activator accepts repeat events of the [character].
///
/// If [includeRepeats] is true, the activator is checked on all
/// [RawKeyDownEvent] events for the [character]. If [includeRepeats] is
/// false, only the [character] events with a false [RawKeyDownEvent.repeat]
/// attribute will be considered.
/// [KeyDownEvent] and [KeyRepeatEvent]s for the [character]. If
/// [includeRepeats] is false, only the [character] events that are
/// [KeyDownEvent]s will be considered.
final bool includeRepeats;
/// The character which triggers the shortcut.
......@@ -694,7 +694,7 @@ class CharacterActivator with Diagnosticable, MenuSerializableShortcut implement
///
/// See also:
///
/// * [RawKeyEvent.character], the character of a key event.
/// * [KeyEvent.character], the character of a key event.
final String character;
@override
......
......@@ -7788,6 +7788,9 @@ void main() {
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
await tester.pump();
expect(focusNode3.hasPrimaryFocus, isTrue);
// TODO(gspencergoog): Remove the variant when the deprecated
// KeySimulatorTransitModeVariant API is removed.
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Scrolling shortcuts are disabled in text fields', (WidgetTester tester) async {
......@@ -7822,6 +7825,9 @@ void main() {
await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
expect(scrollInvoked, isFalse);
// TODO(gspencergoog): Remove the variant when the deprecated
// KeySimulatorTransitModeVariant API is removed.
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Cupertino text field semantics', (WidgetTester tester) async {
......
......@@ -7022,6 +7022,9 @@ void main() {
await tester.sendKeyEvent(LogicalKeyboardKey.arrowLeft);
await tester.sendKeyUpEvent(LogicalKeyboardKey.shift);
expect(controller.selection.extentOffset - controller.selection.baseOffset, -1);
// TODO(gspencergoog): Remove the variant when the deprecated
// KeySimulatorTransitModeVariant API is removed.
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Shift test 2', (WidgetTester tester) async {
......@@ -7040,6 +7043,9 @@ void main() {
await tester.sendKeyDownEvent(LogicalKeyboardKey.arrowRight);
await tester.pumpAndSettle();
expect(controller.selection.extentOffset - controller.selection.baseOffset, 1);
// TODO(gspencergoog): Remove the variant when the deprecated
// KeySimulatorTransitModeVariant API is removed.
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Control Shift test', (WidgetTester tester) async {
......@@ -7057,6 +7063,9 @@ void main() {
await tester.pumpAndSettle();
expect(controller.selection.extentOffset - controller.selection.baseOffset, 5);
// TODO(gspencergoog): Remove the variant when the deprecated
// KeySimulatorTransitModeVariant API is removed.
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Down and up test', (WidgetTester tester) async {
......@@ -7084,6 +7093,9 @@ void main() {
await tester.pumpAndSettle();
expect(controller.selection.extentOffset - controller.selection.baseOffset, 0);
// TODO(gspencergoog): Remove the variant when the deprecated
// KeySimulatorTransitModeVariant API is removed.
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Down and up test 2', (WidgetTester tester) async {
......@@ -7140,6 +7152,9 @@ void main() {
await tester.pumpAndSettle();
expect(controller.selection.extentOffset - controller.selection.baseOffset, -5);
// TODO(gspencergoog): Remove the variant when the deprecated
// KeySimulatorTransitModeVariant API is removed.
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Read only keyboard selection test', (WidgetTester tester) async {
......@@ -7160,6 +7175,9 @@ void main() {
await tester.sendKeyDownEvent(LogicalKeyboardKey.shift);
await tester.sendKeyDownEvent(LogicalKeyboardKey.arrowLeft);
expect(controller.selection.extentOffset - controller.selection.baseOffset, -1);
// TODO(gspencergoog): Remove the variant when the deprecated
// KeySimulatorTransitModeVariant API is removed.
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
}, skip: areKeyEventsHandledByPlatform); // [intended] only applies to platforms where we handle key events.
......@@ -7237,6 +7255,9 @@ void main() {
expect(find.text(expected), findsOneWidget, reason: 'Because text contains ${controller.text}');
},
skip: areKeyEventsHandledByPlatform, // [intended] only applies to platforms where we handle key events.
// TODO(gspencergoog): Remove the variant when the deprecated
// KeySimulatorTransitModeVariant API is removed.
// ignore: deprecated_member_use
variant: KeySimulatorTransitModeVariant.all()
);
......@@ -7290,6 +7311,9 @@ void main() {
expect(find.text(clipboardContent), findsOneWidget);
},
skip: areKeyEventsHandledByPlatform, // [intended] only applies to platforms where we handle key events.
// TODO(gspencergoog): Remove the variant when the deprecated
// KeySimulatorTransitModeVariant API is removed.
// ignore: deprecated_member_use
variant: KeySimulatorTransitModeVariant.all(),
);
......@@ -7369,6 +7393,9 @@ void main() {
expect(find.text(expected), findsOneWidget);
},
skip: areKeyEventsHandledByPlatform, // [intended] only applies to platforms where we handle key events.
// TODO(gspencergoog): Remove the variant when the deprecated
// KeySimulatorTransitModeVariant API is removed.
// ignore: deprecated_member_use
variant: KeySimulatorTransitModeVariant.all()
);
......@@ -7420,6 +7447,9 @@ void main() {
expect(find.text(expected), findsOneWidget);
},
skip: areKeyEventsHandledByPlatform, // [intended] only applies to platforms where we handle key events.
// TODO(gspencergoog): Remove the variant when the deprecated
// KeySimulatorTransitModeVariant API is removed.
// ignore: deprecated_member_use
variant: KeySimulatorTransitModeVariant.all()
);
......@@ -7474,6 +7504,9 @@ void main() {
expect(find.text(expected2), findsOneWidget);
},
skip: areKeyEventsHandledByPlatform, // [intended] only applies to platforms where we handle key events.
// TODO(gspencergoog): Remove the variant when the deprecated
// KeySimulatorTransitModeVariant API is removed.
// ignore: deprecated_member_use
variant: KeySimulatorTransitModeVariant.all(),
);
......@@ -7569,6 +7602,9 @@ void main() {
expect(c1.selection.extentOffset - c1.selection.baseOffset, -10);
},
skip: areKeyEventsHandledByPlatform, // [intended] only applies to platforms where we handle key events.
// TODO(gspencergoog): Remove the variant when the deprecated
// KeySimulatorTransitModeVariant API is removed.
// ignore: deprecated_member_use
variant: KeySimulatorTransitModeVariant.all()
);
......@@ -7646,6 +7682,9 @@ void main() {
expect(c2.selection.extentOffset - c2.selection.baseOffset, -5);
},
skip: areKeyEventsHandledByPlatform, // [intended] only applies to platforms where we handle key events.
// TODO(gspencergoog): Remove the variant when the deprecated
// KeySimulatorTransitModeVariant API is removed.
// ignore: deprecated_member_use
variant: KeySimulatorTransitModeVariant.all()
);
......
......@@ -67,6 +67,7 @@ void main() {
equals(<LogicalKeyboardKey>{}));
expect(HardwareKeyboard.instance.lockModesEnabled,
equals(<KeyboardLockMode>{}));
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.keyDataThenRawKeyData());
testWidgetsWithLeakTracking('KeyEvent can tell which keys are pressed', (WidgetTester tester) async {
......@@ -101,6 +102,7 @@ void main() {
await simulateKeyUpEvent(LogicalKeyboardKey.numLock, platform: 'windows');
expect(HardwareKeyboard.instance.isPhysicalKeyPressed(PhysicalKeyboardKey.numLock), isFalse);
expect(HardwareKeyboard.instance.isLogicalKeyPressed(LogicalKeyboardKey.numLock), isFalse);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.keyDataThenRawKeyData());
testWidgetsWithLeakTracking('KeyboardManager synthesizes modifier keys in rawKeyData mode', (WidgetTester tester) async {
......@@ -228,6 +230,7 @@ void main() {
true);
expect(logs, <int>[3, 2, 1]);
logs.clear();
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
// Regression test for https://github.com/flutter/flutter/issues/99196 .
......@@ -277,6 +280,7 @@ void main() {
expect(ServicesBinding.instance.keyboard.physicalKeysPressed, equals(<PhysicalKeyboardKey>{
PhysicalKeyboardKey.keyA,
}));
// ignore: deprecated_member_use
}, variant: const KeySimulatorTransitModeVariant(<KeyDataTransitMode>{
KeyDataTransitMode.rawKeyData,
}));
......@@ -312,6 +316,7 @@ void main() {
)), false);
expect(logs, <int>[2, 1]);
logs.clear();
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.keyDataThenRawKeyData());
testWidgetsWithLeakTracking('Postpone synthesized key events when the queue is not empty', (WidgetTester tester) async {
......@@ -366,6 +371,7 @@ void main() {
expect(logs, <String>['RawKeyDownEvent', 'KeyDownEvent', 'KeyUpEvent']);
logs.clear();
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.keyDataThenRawKeyData());
// The first key data received from the engine might be an empty key data.
......@@ -505,6 +511,7 @@ void main() {
// If the previous state (key down) wasn't recorded, this key up event will
// trigger assertions.
expect(record, isNull);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('debugPrintKeyboardEvents causes logging of key events', (WidgetTester tester) async {
......
......@@ -1014,6 +1014,7 @@ void main() {
false);
expect(logs, <int>[1, 3, 2]);
logs.clear();
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Exceptions from RawKeyboard listeners are caught and reported', (WidgetTester tester) async {
......@@ -2154,6 +2155,7 @@ void main() {
expect(events, isEmpty);
expect(lastHandled, true);
expect(RawKeyboard.instance.keysPressed, isEmpty);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.keyDataThenRawKeyData());
test('data.toString', () {
......
......@@ -147,6 +147,7 @@ void main() {
await tester.sendKeyEvent(LogicalKeyboardKey.gameButtonA);
await tester.pumpAndSettle();
expect(checked, isTrue);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
group('error control test', () {
......
......@@ -445,6 +445,7 @@ void main() {
debugDefaultTargetPlatformOverride = null;
},
// ignore: deprecated_member_use
variant: KeySimulatorTransitModeVariant.all(),
);
......
......@@ -12559,6 +12559,7 @@ void main() {
expect(controller.selection.isCollapsed, true);
expect(controller.selection.baseOffset, 0);
}
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('the toolbar is disposed when selection changes and there is no selectionControls', (WidgetTester tester) async {
......
......@@ -352,6 +352,7 @@ void main() {
false);
expect(logs, <int>[20, 21, 10, 11]);
logs.clear();
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
});
......@@ -1269,6 +1270,7 @@ void main() {
// Since none of the focused nodes handle this event, nothing should
// receive it.
expect(receivedAnEvent, isEmpty);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Initial highlight mode guesses correctly.', (WidgetTester tester) async {
......@@ -1901,6 +1903,7 @@ void main() {
expect(await simulateKeyDownEvent(LogicalKeyboardKey.digit1), true);
expect(await simulateKeyUpEvent(LogicalKeyboardKey.digit1), false);
expect(logs, <int>[0, 1, 0, 1]);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('FocusManager.addLateKeyEventHandler works', (WidgetTester tester) async {
......@@ -1980,6 +1983,7 @@ void main() {
expect(await simulateKeyDownEvent(LogicalKeyboardKey.digit1), true);
expect(await simulateKeyUpEvent(LogicalKeyboardKey.digit1), false);
expect(logs, <int>[0, 1, 0, 1]);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('FocusManager notifies listeners when a widget loses focus because it was removed.', (WidgetTester tester) async {
......
......@@ -2403,6 +2403,7 @@ void main() {
expect(Focus.of(lowerLeftKey.currentContext!).hasPrimaryFocus, isTrue);
await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp);
expect(Focus.of(upperLeftKey.currentContext!).hasPrimaryFocus, isTrue);
// ignore: deprecated_member_use
}, skip: isBrowser, variant: KeySimulatorTransitModeVariant.all()); // https://github.com/flutter/flutter/issues/35347
testWidgetsWithLeakTracking('Focus traversal actions works when current focus skip traversal', (WidgetTester tester) async {
......@@ -2458,6 +2459,7 @@ void main() {
expect(Focus.of(key2.currentContext!).hasPrimaryFocus, isTrue);
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
expect(Focus.of(key3.currentContext!).hasPrimaryFocus, isTrue);
// ignore: deprecated_member_use
}, skip: isBrowser, variant: KeySimulatorTransitModeVariant.all()); // https://github.com/flutter/flutter/issues/35347
testWidgetsWithLeakTracking('Focus traversal inside a vertical scrollable scrolls to stay visible.', (WidgetTester tester) async {
......@@ -2564,6 +2566,7 @@ void main() {
await tester.pump();
expect(topNode.hasPrimaryFocus, isTrue);
expect(controller.offset, equals(0.0));
// ignore: deprecated_member_use
}, skip: isBrowser, variant: KeySimulatorTransitModeVariant.all()); // https://github.com/flutter/flutter/issues/35347
testWidgetsWithLeakTracking('Focus traversal inside a horizontal scrollable scrolls to stay visible.', (WidgetTester tester) async {
......@@ -2671,6 +2674,7 @@ void main() {
await tester.pump();
expect(leftNode.hasPrimaryFocus, isTrue);
expect(controller.offset, equals(0.0));
// ignore: deprecated_member_use
}, skip: isBrowser, variant: KeySimulatorTransitModeVariant.all()); // https://github.com/flutter/flutter/issues/35347
testWidgetsWithLeakTracking('Arrow focus traversal actions can be re-enabled for text fields.', (WidgetTester tester) async {
......@@ -2802,6 +2806,7 @@ void main() {
expect(focusNodeUpperLeft.hasPrimaryFocus, isTrue);
await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp);
expect(focusNodeUpperLeft.hasPrimaryFocus, isTrue);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Focus traversal does not break when no focusable is available on a MaterialApp', (WidgetTester tester) async {
......@@ -2819,6 +2824,7 @@ void main() {
await tester.idle();
expect(events.length, 2);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Focus traversal does not throw when no focusable is available in a group', (WidgetTester tester) async {
......@@ -2854,6 +2860,7 @@ void main() {
await tester.idle();
expect(events.length, 2);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Custom requestFocusCallback gets called on focusInDirection up/down/left/right.', (WidgetTester tester) async {
......
......@@ -155,6 +155,7 @@ void main() {
tester.getRect(find.byKey(const ValueKey<String>('Box 0'), skipOffstage: false)),
equals(const Rect.fromLTRB(0.0, 0.0, 800.0, 50.0)),
);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Vertical scrollables are scrolled when activated via keyboard.', (WidgetTester tester) async {
......@@ -227,6 +228,7 @@ void main() {
tester.getRect(find.byKey(const ValueKey<String>('Box 0'), skipOffstage: false)),
equals(const Rect.fromLTRB(0.0, 0.0, 800.0, 50.0)),
);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Horizontal scrollables are scrolled when activated via keyboard.', (WidgetTester tester) async {
......@@ -288,6 +290,7 @@ void main() {
tester.getRect(find.byKey(const ValueKey<String>('Box 0'), skipOffstage: false)),
equals(const Rect.fromLTRB(0.0, 0.0, 50.0, 600.0)),
);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Horizontal scrollables are scrolled the correct direction in RTL locales.', (WidgetTester tester) async {
......@@ -352,6 +355,7 @@ void main() {
tester.getRect(find.byKey(const ValueKey<String>('Box 0'), skipOffstage: false)),
equals(const Rect.fromLTRB(750.0, 0.0, 800.0, 600.0)),
);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Reversed vertical scrollables are scrolled when activated via keyboard.', (WidgetTester tester) async {
......@@ -428,6 +432,7 @@ void main() {
tester.getRect(find.byKey(const ValueKey<String>('Box 0'), skipOffstage: false)),
equals(const Rect.fromLTRB(0.0, 550.0, 800.0, 600.0)),
);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Reversed horizontal scrollables are scrolled when activated via keyboard.', (WidgetTester tester) async {
......@@ -489,6 +494,7 @@ void main() {
await tester.sendKeyUpEvent(modifierKey);
}
await tester.pumpAndSettle();
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Custom scrollables with a center sliver are scrolled when activated via keyboard.', (WidgetTester tester) async {
......@@ -561,6 +567,7 @@ void main() {
tester.getRect(find.byKey(const ValueKey<String>('Item 10'), skipOffstage: false)),
equals(const Rect.fromLTRB(0.0, 100.0, 800.0, 200.0)),
);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Can scroll using intents only', (WidgetTester tester) async {
......
......@@ -1689,6 +1689,7 @@ void main() {
await tester.sendKeyDownEvent(LogicalKeyboardKey.shift);
await tester.sendKeyDownEvent(LogicalKeyboardKey.arrowLeft);
expect(controller.selection.extentOffset - controller.selection.baseOffset, -1);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Shift test 2', (WidgetTester tester) async {
......@@ -1701,6 +1702,7 @@ void main() {
await tester.sendKeyDownEvent(LogicalKeyboardKey.arrowRight);
await tester.pumpAndSettle();
expect(controller.selection.extentOffset - controller.selection.baseOffset, 1);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Control Shift test', (WidgetTester tester) async {
......@@ -1713,6 +1715,7 @@ void main() {
await tester.pumpAndSettle();
expect(controller.selection.extentOffset - controller.selection.baseOffset, -5);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Down and up test', (WidgetTester tester) async {
......@@ -1731,6 +1734,7 @@ void main() {
await tester.pumpAndSettle();
expect(controller.selection.extentOffset - controller.selection.baseOffset, 0);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Down and up test 2', (WidgetTester tester) async {
......@@ -1782,6 +1786,7 @@ void main() {
await tester.pumpAndSettle();
expect(controller.selection.extentOffset - controller.selection.baseOffset, -5);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
});
......@@ -1842,6 +1847,7 @@ void main() {
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
await tester.pumpAndSettle();
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Select all test', (WidgetTester tester) async {
......@@ -1877,6 +1883,7 @@ void main() {
expect(controller.selection.baseOffset, 0);
expect(controller.selection.extentOffset, 31);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('keyboard selection should call onSelectionChanged', (WidgetTester tester) async {
......@@ -1924,6 +1931,7 @@ void main() {
expect(newSelection!.extentOffset, i + 1);
newSelection = null;
}
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Changing positions of selectable text', (WidgetTester tester) async {
......@@ -2015,6 +2023,7 @@ void main() {
c1 = editableTextWidget.controller;
expect(c1.selection.extentOffset - c1.selection.baseOffset, -10);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Changing focus test', (WidgetTester tester) async {
......@@ -2085,6 +2094,7 @@ void main() {
expect(c1.selection.extentOffset - c1.selection.baseOffset, -5);
expect(c2.selection.extentOffset - c2.selection.baseOffset, -5);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Caret works when maxLines is null', (WidgetTester tester) async {
......
......@@ -353,6 +353,7 @@ void main() {
invoked = 0;
expect(HardwareKeyboard.instance.logicalKeysPressed, isEmpty);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('handles repeated events', (WidgetTester tester) async {
......@@ -379,6 +380,7 @@ void main() {
invoked = 0;
expect(HardwareKeyboard.instance.logicalKeysPressed, isEmpty);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('rejects repeated events if requested', (WidgetTester tester) async {
......@@ -406,6 +408,7 @@ void main() {
invoked = 0;
expect(HardwareKeyboard.instance.logicalKeysPressed, isEmpty);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('handles Shift-Ctrl-C', (WidgetTester tester) async {
......@@ -1169,6 +1172,7 @@ void main() {
await tester.sendKeyUpEvent(LogicalKeyboardKey.shiftLeft);
expect(invoked, 1);
invoked = 0;
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('handles repeated events', (WidgetTester tester) async {
......@@ -1189,6 +1193,7 @@ void main() {
await tester.sendKeyUpEvent(LogicalKeyboardKey.shiftLeft);
expect(invoked, 2);
invoked = 0;
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('rejects repeated events if requested', (WidgetTester tester) async {
......@@ -1209,6 +1214,7 @@ void main() {
await tester.sendKeyUpEvent(LogicalKeyboardKey.shiftLeft);
expect(invoked, 1);
invoked = 0;
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('handles Alt, Ctrl and Meta', (WidgetTester tester) async {
......@@ -1255,6 +1261,7 @@ void main() {
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlRight);
expect(invoked, 1);
invoked = 0;
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('isActivatedBy works as expected', (WidgetTester tester) async {
......
......@@ -1159,17 +1159,18 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
}
_announcements = <CapturedAccessibilityAnnouncement>[];
// ignore: deprecated_member_use
ServicesBinding.instance.keyEventManager.keyMessageHandler = null;
buildOwner!.focusManager = FocusManager()..registerGlobalHandlers();
// Disabling the warning because @visibleForTesting doesn't take the testing
// framework itself into account, but we don't want it visible outside of
// tests.
// ignore: invalid_use_of_visible_for_testing_member
// ignore: invalid_use_of_visible_for_testing_member, deprecated_member_use
RawKeyboard.instance.clearKeysPressed();
// ignore: invalid_use_of_visible_for_testing_member
HardwareKeyboard.instance.clearState();
// ignore: invalid_use_of_visible_for_testing_member
// ignore: invalid_use_of_visible_for_testing_member, deprecated_member_use
keyEventManager.clearState();
// ignore: invalid_use_of_visible_for_testing_member
RendererBinding.instance.initMouseTracker();
......
......@@ -1858,9 +1858,6 @@ abstract class WidgetController {
/// simulated event. If not specified, it uses a default derived from the
/// logical `key`.
///
/// Whether the event is sent through [RawKeyEvent] or [KeyEvent] is
/// controlled by [debugKeyEventSimulatorTransitModeOverride].
///
/// Keys that are down when the test completes are cleared after each test.
///
/// This method sends both the key down and the key up events, to simulate a
......@@ -1903,9 +1900,6 @@ abstract class WidgetController {
/// simulated event. If not specified, it uses a default derived from the
/// logical `key`.
///
/// Whether the event is sent through [RawKeyEvent] or [KeyEvent] is
/// controlled by [debugKeyEventSimulatorTransitModeOverride].
///
/// Keys that are down when the test completes are cleared after each test.
///
/// Returns true if the key event was handled by the framework.
......@@ -1939,9 +1933,6 @@ abstract class WidgetController {
/// the simulated event. If not specified, it uses a default from the US
/// keyboard layout for the corresponding logical `key`.
///
/// Whether the event is sent through [RawKeyEvent] or [KeyEvent] is
/// controlled by [debugKeyEventSimulatorTransitModeOverride].
///
/// Returns true if the key event was handled by the framework.
///
/// See also:
......@@ -1976,10 +1967,6 @@ abstract class WidgetController {
/// simulated event. If not specified, it uses a default derived from the
/// logical `key`.
///
/// Whether the event is sent through [RawKeyEvent] or [KeyEvent] is
/// controlled by [debugKeyEventSimulatorTransitModeOverride]. If through [RawKeyEvent],
/// this method is equivalent to [sendKeyDownEvent].
///
/// Keys that are down when the test completes are cleared after each test.
///
/// Returns true if the key event was handled by the framework.
......
......@@ -17,6 +17,7 @@ void _verifyKeyEvent<T extends KeyEvent>(KeyEvent event, PhysicalKeyboardKey phy
expect(event.synthesized, false);
}
// ignore: deprecated_member_use
void _verifyRawKeyEvent<T extends RawKeyEvent>(RawKeyEvent event, PhysicalKeyboardKey physical, LogicalKeyboardKey logical, String? character) {
expect(event, isA<T>());
expect(event.physicalKey, physical);
......@@ -38,13 +39,16 @@ Future<void> _shouldThrow<T extends Error>(AsyncValueGetter<void> func) async {
void main() {
testWidgets('simulates keyboard events (RawEvent)', (WidgetTester tester) async {
// ignore: deprecated_member_use
debugKeyEventSimulatorTransitModeOverride = KeyDataTransitMode.rawKeyData;
// ignore: deprecated_member_use
final List<RawKeyEvent> events = <RawKeyEvent>[];
final FocusNode focusNode = FocusNode();
await tester.pumpWidget(
// ignore: deprecated_member_use
RawKeyboardListener(
focusNode: focusNode,
onKey: events.add,
......@@ -68,11 +72,14 @@ void main() {
for (int i = 0; i < events.length; ++i) {
final bool isEven = i.isEven;
if (isEven) {
// ignore: deprecated_member_use
expect(events[i].runtimeType, equals(RawKeyDownEvent));
} else {
// ignore: deprecated_member_use
expect(events[i].runtimeType, equals(RawKeyUpEvent));
}
if (i < 4) {
// ignore: deprecated_member_use
expect(events[i].data.isModifierPressed(ModifierKey.shiftModifier, side: KeyboardSide.left), equals(isEven));
}
}
......@@ -82,10 +89,12 @@ void main() {
await tester.pumpWidget(Container());
focusNode.dispose();
// ignore: deprecated_member_use
debugKeyEventSimulatorTransitModeOverride = null;
});
testWidgets('simulates keyboard events (KeyData then RawKeyEvent)', (WidgetTester tester) async {
// ignore: deprecated_member_use
debugKeyEventSimulatorTransitModeOverride = KeyDataTransitMode.keyDataThenRawKeyData;
final List<KeyEvent> events = <KeyEvent>[];
......@@ -245,10 +254,12 @@ void main() {
await tester.pumpWidget(Container());
focusNode.dispose();
// ignore: deprecated_member_use
debugKeyEventSimulatorTransitModeOverride = null;
});
testWidgets('simulates using the correct transit mode: rawKeyData', (WidgetTester tester) async {
// ignore: deprecated_member_use
debugKeyEventSimulatorTransitModeOverride = KeyDataTransitMode.rawKeyData;
final List<Object> events = <Object>[];
......@@ -257,6 +268,7 @@ void main() {
await tester.pumpWidget(
Focus(
focusNode: focusNode,
// ignore: deprecated_member_use
onKey: (FocusNode node, RawKeyEvent event) {
events.add(event);
return KeyEventResult.ignored;
......@@ -277,7 +289,9 @@ void main() {
expect(events.length, 2);
expect(events[0], isA<KeyEvent>());
_verifyKeyEvent<KeyDownEvent>(events[0] as KeyEvent, PhysicalKeyboardKey.keyA, LogicalKeyboardKey.keyA, 'a');
// ignore: deprecated_member_use
expect(events[1], isA<RawKeyEvent>());
// ignore: deprecated_member_use
_verifyRawKeyEvent<RawKeyDownEvent>(events[1] as RawKeyEvent, PhysicalKeyboardKey.keyA, LogicalKeyboardKey.keyA, 'a');
events.clear();
......@@ -289,22 +303,27 @@ void main() {
expect(events.length, 2);
expect(events[0], isA<KeyEvent>());
_verifyKeyEvent<KeyUpEvent>(events[0] as KeyEvent, PhysicalKeyboardKey.keyA, LogicalKeyboardKey.keyA, null);
// ignore: deprecated_member_use
expect(events[1], isA<RawKeyEvent>());
// ignore: deprecated_member_use
_verifyRawKeyEvent<RawKeyUpEvent>(events[1] as RawKeyEvent, PhysicalKeyboardKey.keyA, LogicalKeyboardKey.keyB, null);
events.clear();
// Manually switch the transit mode to `keyDataThenRawKeyData`. This will
// never happen in real applications so the assertion error can verify that
// the transit mode is correctly applied.
// ignore: deprecated_member_use
debugKeyEventSimulatorTransitModeOverride = KeyDataTransitMode.keyDataThenRawKeyData;
await _shouldThrow<AssertionError>(() =>
simulateKeyUpEvent(LogicalKeyboardKey.keyB, physicalKey: PhysicalKeyboardKey.keyA));
// ignore: deprecated_member_use
debugKeyEventSimulatorTransitModeOverride = null;
});
testWidgets('simulates using the correct transit mode: keyDataThenRawKeyData', (WidgetTester tester) async {
// ignore: deprecated_member_use
debugKeyEventSimulatorTransitModeOverride = KeyDataTransitMode.keyDataThenRawKeyData;
final List<Object> events = <Object>[];
......@@ -313,6 +332,7 @@ void main() {
await tester.pumpWidget(
Focus(
focusNode: focusNode,
// ignore: deprecated_member_use
onKey: (FocusNode node, RawKeyEvent event) {
events.add(event);
return KeyEventResult.ignored;
......@@ -333,7 +353,9 @@ void main() {
expect(events.length, 2);
expect(events[0], isA<KeyEvent>());
_verifyKeyEvent<KeyDownEvent>(events[0] as KeyEvent, PhysicalKeyboardKey.keyA, LogicalKeyboardKey.keyA, 'a');
// ignore: deprecated_member_use
expect(events[1], isA<RawKeyEvent>());
// ignore: deprecated_member_use
_verifyRawKeyEvent<RawKeyDownEvent>(events[1] as RawKeyEvent, PhysicalKeyboardKey.keyA, LogicalKeyboardKey.keyA, 'a');
events.clear();
......@@ -345,6 +367,7 @@ void main() {
await _shouldThrow<AssertionError>(() =>
simulateKeyUpEvent(LogicalKeyboardKey.keyB, physicalKey: PhysicalKeyboardKey.keyA));
// ignore: deprecated_member_use
debugKeyEventSimulatorTransitModeOverride = null;
});
}
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