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