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
This commit is contained in:
Greg Spencer 2023-12-11 14:19:18 -08:00 committed by GitHub
parent 97190973d6
commit a33dec1a27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
33 changed files with 784 additions and 195 deletions

View File

@ -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() {

View File

@ -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 {
/// 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 {
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

View File

@ -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

View File

@ -17,7 +17,6 @@ export 'dart:ui' show KeyData;
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 RawKeyEvent, RawKeyboard;
// When using _keyboardDebug, always call it like so: // When using _keyboardDebug, always call it like so:
// //
@ -401,31 +400,11 @@ typedef KeyEventCallback = bool Function(KeyEvent event);
/// resolve any conflicts and provide a regularized key event stream, which /// resolve any conflicts and provide a regularized key event stream, which
/// can deviate from the ground truth. /// can deviate from the ground truth.
/// ///
/// ## Compared to [RawKeyboard]
///
/// [RawKeyboard] is the legacy API, and will be deprecated and removed in the
/// future. It is recommended to always use [HardwareKeyboard] and [KeyEvent]
/// APIs (such as [FocusNode.onKeyEvent]) to handle key events.
///
/// Behavior-wise, [RawKeyboard] provides a less unified, less regular
/// event model than [HardwareKeyboard]. For example:
///
/// * Down events might not be matched with an up event, and vice versa (the
/// set of pressed keys is silently updated).
/// * The logical key of the down event might not be the same as that of the up
/// event.
/// * Down events and repeat events are not easily distinguishable (must be
/// tracked manually).
/// * Lock modes (such as CapsLock) only have their "enabled" state recorded.
/// There's no way to acquire their pressing state.
///
/// See also: /// See also:
/// ///
/// * [KeyDownEvent], [KeyRepeatEvent], and [KeyUpEvent], the classes used to /// * [KeyDownEvent], [KeyRepeatEvent], and [KeyUpEvent], the classes used to
/// describe specific key events. /// describe specific key events.
/// * [instance], the singleton instance of this class. /// * [instance], the singleton instance of this class.
/// * [RawKeyboard], the legacy API that dispatches key events containing raw
/// system data.
class HardwareKeyboard { class HardwareKeyboard {
/// Provides convenient access to the current [HardwareKeyboard] singleton from /// Provides convenient access to the current [HardwareKeyboard] singleton from
/// the [ServicesBinding] instance. /// the [ServicesBinding] instance.
@ -701,6 +680,10 @@ class HardwareKeyboard {
/// The mode in which information of key messages is delivered. /// The mode in which information of key messages is delivered.
/// ///
/// This enum is deprecated and will be removed. There is no direct substitute
/// planned, since this enum will no longer be necessary once [RawKeyEvent] and
/// associated APIs are removed.
///
/// Different platforms use different methods, classes, and models to inform the /// Different platforms use different methods, classes, and models to inform the
/// framework of native key events, which is called "transit mode". /// framework of native key events, which is called "transit mode".
/// ///
@ -714,12 +697,16 @@ class HardwareKeyboard {
/// ///
/// See also: /// See also:
/// ///
/// * [KeyEventManager], which infers the transit mode of the current platform /// * [KeyEventManager], which infers the transit mode of the current platform
/// and guides how key messages are dispatched. /// and guides how key messages are dispatched.
/// * [debugKeyEventSimulatorTransitModeOverride], overrides the transit mode /// * [debugKeyEventSimulatorTransitModeOverride], overrides the transit mode
/// used to simulate key events. /// used to simulate key events.
/// * [KeySimulatorTransitModeVariant], an easier way to set /// * [KeySimulatorTransitModeVariant], an easier way to set
/// [debugKeyEventSimulatorTransitModeOverride] in widget tests. /// [debugKeyEventSimulatorTransitModeOverride] in widget tests.
@Deprecated(
'No longer supported. Transit mode is always key data only. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
enum KeyDataTransitMode { enum KeyDataTransitMode {
/// Key event information is delivered as raw key data. /// Key event information is delivered as raw key data.
/// ///
@ -729,6 +716,10 @@ enum KeyDataTransitMode {
/// ///
/// If the current transit mode is [rawKeyData], the raw key data is converted /// If the current transit mode is [rawKeyData], the raw key data is converted
/// to both [KeyMessage.events] and [KeyMessage.rawEvent]. /// to both [KeyMessage.events] and [KeyMessage.rawEvent].
@Deprecated(
'No longer supported. Transit mode is always key data only. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
rawKeyData, rawKeyData,
/// Key event information is delivered as converted key data, followed by raw /// Key event information is delivered as converted key data, followed by raw
@ -745,39 +736,48 @@ enum KeyDataTransitMode {
/// If the current transit mode is [keyDataThenRawKeyData], then the /// If the current transit mode is [keyDataThenRawKeyData], then the
/// [KeyEventManager] will use the [ui.KeyData] for [KeyMessage.events], and /// [KeyEventManager] will use the [ui.KeyData] for [KeyMessage.events], and
/// the raw data for [KeyMessage.rawEvent]. /// the raw data for [KeyMessage.rawEvent].
@Deprecated(
'No longer supported. Transit mode is always key data only. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
keyDataThenRawKeyData, keyDataThenRawKeyData,
} }
/// The assembled information converted from a native key message. /// The assembled information converted from a native key message.
/// ///
/// Native key messages, produced by physically pressing or releasing /// This class is deprecated, and will be removed. There is no direct substitute
/// keyboard keys, are translated into two different event streams in Flutter: /// planned, since this class will no longer be necessary once [RawKeyEvent] and
/// associated APIs are removed.
/// ///
/// * The [KeyEvent] stream, represented by [KeyMessage.events] (recommended). /// Native key messages, produced by physically pressing or releasing keyboard
/// * The [RawKeyEvent] stream, represented by [KeyMessage.rawEvent] (legacy, /// keys, are translated into two different event streams in Flutter:
/// to be deprecated). ///
/// * The [KeyEvent] stream, represented by [KeyMessage.events] (recommended).
/// * The [RawKeyEvent] stream, represented by [KeyMessage.rawEvent] (legacy, to
/// be deprecated).
/// ///
/// Either the [KeyEvent] stream or the [RawKeyEvent] stream alone provides a /// Either the [KeyEvent] stream or the [RawKeyEvent] stream alone provides a
/// complete description of the keyboard messages, but in different event /// complete description of the keyboard messages, but in different event
/// models. Flutter is still transitioning from the legacy model to the new /// models. Flutter is still transitioning from the legacy model to the new
/// model, therefore it dispatches both streams simultaneously until the /// model, therefore it dispatches both streams simultaneously until the
/// transition is completed. [KeyMessage] is used to bundle the /// transition is completed. [KeyMessage] is used to bundle the stream segments
/// stream segments of both models from a native key message together for the /// of both models from a native key message together for the convenience of
/// convenience of propagation. /// propagation.
/// ///
/// Typically, an application either processes [KeyMessage.events] /// Typically, an application either processes [KeyMessage.events] or
/// or [KeyMessage.rawEvent], not both. For example, handling a /// [KeyMessage.rawEvent], not both. For example, handling a [KeyMessage], means
/// [KeyMessage], means handling each event in [KeyMessage.events]. /// handling each event in [KeyMessage.events].
/// ///
/// In advanced cases, a widget needs to process both streams at the same time. /// In advanced cases, a widget needs to process both streams at the same time.
/// For example, [FocusNode] has an `onKey` that dispatches [RawKeyEvent]s and /// For example, [FocusNode] has an `onKey` that dispatches [RawKeyEvent]s and
/// an `onKeyEvent` that dispatches [KeyEvent]s. To processes a [KeyMessage], /// an `onKeyEvent` that dispatches [KeyEvent]s. To processes a [KeyMessage], it
/// it first calls `onKeyEvent` with each [KeyEvent] of [events], and then /// first calls `onKeyEvent` with each [KeyEvent] of [events], and then `onKey`
/// `onKey` with [rawEvent]. All callbacks are invoked regardless of their /// with [rawEvent]. All callbacks are invoked regardless of their
/// [KeyEventResult]. Their results are combined into the result of the node /// [KeyEventResult]. Their results are combined into the result of the node
/// using [combineKeyEventResults]. /// using [combineKeyEventResults].
/// ///
/// ```dart /// ```dart
/// // ignore: deprecated_member_use
/// void handleMessage(FocusNode node, KeyMessage message) { /// void handleMessage(FocusNode node, KeyMessage message) {
/// final List<KeyEventResult> results = <KeyEventResult>[]; /// final List<KeyEventResult> results = <KeyEventResult>[];
/// if (node.onKeyEvent != null) { /// if (node.onKeyEvent != null) {
@ -785,18 +785,28 @@ enum KeyDataTransitMode {
/// results.add(node.onKeyEvent!(node, event)); /// results.add(node.onKeyEvent!(node, event));
/// } /// }
/// } /// }
/// // ignore: deprecated_member_use
/// if (node.onKey != null && message.rawEvent != null) { /// if (node.onKey != null && message.rawEvent != null) {
/// // ignore: deprecated_member_use
/// results.add(node.onKey!(node, message.rawEvent!)); /// results.add(node.onKey!(node, message.rawEvent!));
/// } /// }
/// final KeyEventResult result = combineKeyEventResults(results); /// final KeyEventResult result = combineKeyEventResults(results);
/// // Progress based on `result`... /// // Progress based on `result`...
/// } /// }
/// ``` /// ```
@Deprecated(
'No longer supported. Once RawKeyEvent is removed, it will no longer be needed. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
@immutable @immutable
class KeyMessage { class KeyMessage {
/// Create a [KeyMessage] by providing all information. /// Create a [KeyMessage] by providing all information.
/// ///
/// The [events] might be empty. /// The [events] might be empty.
@Deprecated(
'No longer supported. Once RawKeyEvent is removed, will no longer be needed. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
const KeyMessage(this.events, this.rawEvent); const KeyMessage(this.events, this.rawEvent);
/// The list of [KeyEvent]s converted from the native key message. /// The list of [KeyEvent]s converted from the native key message.
@ -838,34 +848,47 @@ class KeyMessage {
/// The signature for [KeyEventManager.keyMessageHandler]. /// The signature for [KeyEventManager.keyMessageHandler].
/// ///
/// A [KeyMessageHandler] processes a [KeyMessage] and returns whether /// A [KeyMessageHandler] processes a [KeyMessage] and returns whether the
/// the message is considered handled. Handled messages should not be /// message is considered handled. Handled messages should not be propagated to
/// propagated to other native components. /// other native components.
///
/// This message handler signature is deprecated, and will be removed. There is
/// no direct substitute planned, since this handler type will no longer be
/// necessary once [RawKeyEvent] and associated APIs are removed.
@Deprecated(
'No longer supported. Once KeyMessage is removed, will no longer be needed. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
typedef KeyMessageHandler = bool Function(KeyMessage message); typedef KeyMessageHandler = bool Function(KeyMessage message);
/// A singleton class that processes key messages from the platform and /// A singleton class that processes key messages from the platform and
/// dispatches converted messages accordingly. /// dispatches converted messages accordingly.
/// ///
/// [KeyEventManager] receives platform key messages by [handleKeyData] /// This class is deprecated, and will be removed. There is no direct substitute
/// and [handleRawKeyMessage], sends converted events to [HardwareKeyboard] /// planned, since this class will no longer be necessary once [RawKeyEvent] and
/// and [RawKeyboard] for recording keeping, and then dispatches the [KeyMessage] /// associated APIs are removed.
/// to [keyMessageHandler], the global message handler. ///
/// [KeyEventManager] receives platform key messages by [handleKeyData] and
/// [handleRawKeyMessage], sends converted events to [HardwareKeyboard] and
/// [RawKeyboard] for recording keeping, and then dispatches the [KeyMessage] to
/// [keyMessageHandler], the global message handler.
/// ///
/// [KeyEventManager] is typically created, owned, and invoked by /// [KeyEventManager] is typically created, owned, and invoked by
/// [ServicesBinding]. /// [ServicesBinding].
/// ///
/// ## On embedder implementation /// ## On embedder implementation
/// ///
/// Currently, Flutter has two sets of key event APIs running in parallel. /// Currently, Flutter has two sets of key event API pathways running in
/// parallel.
/// ///
/// * The legacy "raw key event" route receives messages from the /// * The "hardware key event" pathway receives messages from the
/// "flutter/keyevent" message channel ([SystemChannels.keyEvent]) and
/// dispatches [RawKeyEvent] to [RawKeyboard] and [Focus.onKey] as well as
/// similar methods.
/// * The newer "hardware key event" route receives messages from the
/// "flutter/keydata" message channel (embedder API /// "flutter/keydata" message channel (embedder API
/// `FlutterEngineSendKeyEvent`) and dispatches [KeyEvent] to /// `FlutterEngineSendKeyEvent`) and dispatches [KeyEvent] to
/// [HardwareKeyboard] and some methods such as [Focus.onKeyEvent]. /// [HardwareKeyboard] and some methods such as [Focus.onKeyEvent].
/// * The deprecated "raw key event" pathway receives messages from the
/// "flutter/keyevent" message channel ([SystemChannels.keyEvent]) and
/// dispatches [RawKeyEvent] to [RawKeyboard] and [Focus.onKey] as well as
/// similar methods. This pathway will be removed at a future date.
/// ///
/// [KeyEventManager] resolves cross-platform compatibility of keyboard /// [KeyEventManager] resolves cross-platform compatibility of keyboard
/// implementations, since legacy platforms might have not implemented the new /// implementations, since legacy platforms might have not implemented the new
@ -874,32 +897,44 @@ typedef KeyMessageHandler = bool Function(KeyMessage message);
/// message comes from platform channel "flutter/keyevent" before one from /// message comes from platform channel "flutter/keyevent" before one from
/// "flutter/keydata", or vice versa, at the beginning of the app. /// "flutter/keydata", or vice versa, at the beginning of the app.
/// ///
/// * If a "flutter/keydata" message is received first, then this platform is
/// considered a modern platform. The hardware key events are stored, and
/// dispatched only when a raw key message is received.
/// * If a "flutter/keyevent" message is received first, then this platform is /// * If a "flutter/keyevent" message is received first, then this platform is
/// considered a legacy platform. The raw key event is transformed into a /// considered a legacy platform. The raw key event is transformed into a
/// hardware key event at best effort. No messages from "flutter/keydata" are /// hardware key event at best effort. No messages from "flutter/keydata" are
/// expected. /// expected. This behavior has been deprecated, and will be removed at a
/// * If a "flutter/keydata" message is received first, then this platform is /// future date.
/// considered a newer platform. The hardware key events are stored, and
/// dispatched only when a raw key message is received.
/// ///
/// Therefore, to correctly implement a platform that supports /// Therefore, to correctly implement a platform that supports
/// `FlutterEngineSendKeyEvent`, the platform must ensure that /// `FlutterEngineSendKeyEvent`, the platform must ensure that
/// `FlutterEngineSendKeyEvent` is called before sending a message to /// `FlutterEngineSendKeyEvent` is called before sending a message to
/// "flutter/keyevent" at the beginning of the app, and every physical key event /// "flutter/keyevent" at the beginning of the app, and every physical key event
/// is ended with a "flutter/keyevent" message. /// is ended with a "flutter/keyevent" message.
@Deprecated(
'No longer supported. Once RawKeyEvent is removed, will no longer be needed. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
class KeyEventManager { class KeyEventManager {
/// Create an instance. /// Create an instance.
/// ///
/// This is typically only called by [ServicesBinding]. /// This is typically only called by [ServicesBinding].
@Deprecated(
'No longer supported. Once RawKeyEvent is removed, will no longer be needed. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
KeyEventManager(this._hardwareKeyboard, this._rawKeyboard); KeyEventManager(this._hardwareKeyboard, this._rawKeyboard);
/// The global entrance which handles all key events sent to Flutter. /// The global entrance which handles all key events sent to Flutter.
/// ///
/// Typical applications use [WidgetsBinding], where this field is /// This handler is deprecated and will be removed. Use
/// set by the focus system (see `FocusManager`) on startup to a function that /// [HardwareKeyboard.addHandler]/[HardwareKeyboard.removeHandler] instead.
/// dispatches incoming events to the focus system, including ///
/// `FocusNode.onKey`, `FocusNode.onKeyEvent`, and `Shortcuts`. In this case, /// Typical applications use [WidgetsBinding], where this field is set by the
/// the application does not need to read, assign, or invoke this value. /// focus system (see `FocusManager`) on startup to a function that dispatches
/// incoming events to the focus system, including `FocusNode.onKey`,
/// `FocusNode.onKeyEvent`, and `Shortcuts`. In this case, the application
/// does not need to read, assign, or invoke this value.
/// ///
/// For advanced uses, the application can "patch" this callback. See below /// For advanced uses, the application can "patch" this callback. See below
/// for details. /// for details.
@ -915,32 +950,32 @@ class KeyEventManager {
/// 4. Other native components (possibly non-Flutter). /// 4. Other native components (possibly non-Flutter).
/// ///
/// Each phase will conclude with a boolean called an "event result". If the /// Each phase will conclude with a boolean called an "event result". If the
/// result is true, this phase _handles_ the event and prevents the event /// result is true, this phase _handles_ the event and prevents the event from
/// from being propagated to the next phase. This mechanism allows shortcuts /// being propagated to the next phase. This mechanism allows shortcuts such
/// such as "Ctrl-C" to not generate a text "C" in the text field, or /// as "Ctrl-C" to not generate a text "C" in the text field, or shortcuts
/// shortcuts that are not handled by any components to trigger special alerts /// that are not handled by any components to trigger special alerts (such as
/// (such as the "bonk" noise on macOS). /// the "bonk" noise on macOS).
/// ///
/// In the second phase, known as "the key event system", the event is dispatched /// In the second phase, known as "the key event system", the event is
/// to several destinations: [RawKeyboard]'s listeners, /// dispatched to several destinations: [RawKeyboard]'s listeners,
/// [HardwareKeyboard]'s handlers, and [keyMessageHandler]. /// [HardwareKeyboard]'s handlers, and [keyMessageHandler]. All destinations
/// All destinations will always receive the event regardless of the handlers' /// will always receive the event regardless of the handlers' results. If any
/// results. If any handler's result is true, then the overall result of the /// handler's result is true, then the overall result of the second phase is
/// second phase is true, and event propagation is stopped. /// true, and event propagation is stopped.
/// ///
/// See also: /// See also:
/// ///
/// * [RawKeyboard.addListener], which adds a raw keyboard listener. /// * [RawKeyboard.addListener], which adds a raw keyboard listener.
/// * [RawKeyboardListener], which is also implemented by adding a raw /// * [RawKeyboardListener], which is also implemented by adding a raw
/// keyboard listener. /// keyboard listener.
/// * [HardwareKeyboard.addHandler], which adds a hardware keyboard handler. /// * [HardwareKeyboard.addHandler], which adds a hardware keyboard handler.
/// ///
/// ## Advanced usages: Manual assignment or patching /// ## Advanced usages: Manual assignment or patching
/// ///
/// If you are not using the focus system to manage focus, set this /// If you are not using the focus system to manage focus, set this attribute
/// attribute to a [KeyMessageHandler] that returns true if the propagation /// to a [KeyMessageHandler] that returns true if the propagation on the
/// on the platform should not be continued. If this field is null, key events /// platform should not be continued. If this field is null, key events will
/// will be assumed to not have been handled by Flutter, a result of "false". /// be assumed to not have been handled by Flutter, a result of "false".
/// ///
/// Even if you are using the focus system, you might also want to do more /// Even if you are using the focus system, you might also want to do more
/// than the focus system allows. In these cases, you can _patch_ /// than the focus system allows. In these cases, you can _patch_
@ -952,20 +987,22 @@ class KeyEventManager {
/// This means that you might want to write your own global notification /// This means that you might want to write your own global notification
/// manager, to which callbacks can be added and removed. /// manager, to which callbacks can be added and removed.
/// ///
/// You should not patch [keyMessageHandler] until the `FocusManager` has assigned /// You should not patch [keyMessageHandler] until the `FocusManager` has
/// its callback. This is assured during any time within the widget lifecycle /// assigned its callback. This is assured during any time within the widget
/// (such as `initState`), or after calling `WidgetManager.instance`. /// lifecycle (such as `initState`), or after calling
/// `WidgetManager.instance`.
/// ///
/// {@tool dartpad} /// {@tool dartpad}
/// This example shows how to process key events that are not handled by any /// This example shows how to process key events that are not
/// focus handler (such as `Shortcuts`) by patching [keyMessageHandler]. /// handled by any focus handler (such as `Shortcuts`) by patching
/// [keyMessageHandler].
/// ///
/// The app prints out any key events that are not handled by the app body. /// The app prints out any key events that are not handled by the app body.
/// Try typing something in the first text field. These key presses are not /// Try typing something in the first text field. These key presses are not
/// handled by `Shortcuts` and will be sent to the fallback handler and printed /// handled by `Shortcuts` and will be sent to the fallback handler and
/// out. Now try some text shortcuts, such as Ctrl+A. The KeyA press is /// printed out. Now try some text shortcuts, such as Ctrl+A. The KeyA press
/// handled as a shortcut, and is not sent to the fallback handler and so is /// is handled as a shortcut, and is not sent to the fallback handler and so
/// not printed out. /// is not printed out.
/// ///
/// The key widget is `FallbackKeyEventRegistrar`, a necessity class to allow /// The key widget is `FallbackKeyEventRegistrar`, a necessity class to allow
/// reversible patching. `FallbackFocus` and `FallbackFocusNode` are also /// reversible patching. `FallbackFocus` and `FallbackFocusNode` are also
@ -977,8 +1014,12 @@ class KeyEventManager {
/// ///
/// See also: /// See also:
/// ///
/// * [HardwareKeyboard.addHandler], which accepts multiple global handlers /// * [HardwareKeyboard.addHandler], which accepts multiple global handlers to
/// to process [KeyEvent]s /// process [KeyEvent]s
@Deprecated(
'No longer supported. Once RawKeyEvent is removed, will no longer be needed. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
KeyMessageHandler? keyMessageHandler; KeyMessageHandler? keyMessageHandler;
final HardwareKeyboard _hardwareKeyboard; final HardwareKeyboard _hardwareKeyboard;
@ -1012,6 +1053,13 @@ class KeyEventManager {
/// Dispatch a key data to global and leaf listeners. /// Dispatch a key data to global and leaf listeners.
/// ///
/// This method is the handler to the global `onKeyData` API. /// This method is the handler to the global `onKeyData` API.
///
/// This handler is deprecated, and will be removed. Use
/// [HardwareKeyboard.addHandler] instead.
@Deprecated(
'No longer supported. Use HardwareKeyboard.instance.addHandler instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
bool handleKeyData(ui.KeyData data) { bool handleKeyData(ui.KeyData data) {
_transitMode ??= KeyDataTransitMode.keyDataThenRawKeyData; _transitMode ??= KeyDataTransitMode.keyDataThenRawKeyData;
switch (_transitMode!) { switch (_transitMode!) {
@ -1075,9 +1123,16 @@ class KeyEventManager {
/// Handles a raw key message. /// Handles a raw key message.
/// ///
/// This method is the handler to [SystemChannels.keyEvent], processing /// This method is the handler to [SystemChannels.keyEvent], processing the
/// the JSON form of the native key message and returns the responds for the /// JSON form of the native key message and returns the responds for the
/// channel. /// channel.
///
/// This handler is deprecated, and will be removed. Use
/// [HardwareKeyboard.addHandler] instead.
@Deprecated(
'No longer supported. Use HardwareKeyboard.instance.addHandler instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
Future<Map<String, dynamic>> handleRawKeyMessage(dynamic message) async { Future<Map<String, dynamic>> handleRawKeyMessage(dynamic message) async {
if (_transitMode == null) { if (_transitMode == null) {
_transitMode = KeyDataTransitMode.rawKeyData; _transitMode = KeyDataTransitMode.rawKeyData;

View File

@ -25,10 +25,18 @@ export 'keyboard_key.g.dart' show LogicalKeyboardKey, PhysicalKeyboardKey;
/// discrimination between which key is pressed (e.g. the left or right SHIFT /// discrimination between which key is pressed (e.g. the left or right SHIFT
/// key). /// key).
/// ///
/// This enum is deprecated and will be removed. There is no direct substitute
/// planned, since this enum will no longer be necessary once [RawKeyEvent] and
/// associated APIs are removed.
///
/// See also: /// See also:
/// ///
/// * [RawKeyEventData.isModifierPressed], which accepts this enum as an /// * [RawKeyEventData.isModifierPressed], which accepts this enum as an
/// argument. /// argument.
@Deprecated(
'No longer supported. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
enum KeyboardSide { enum KeyboardSide {
/// Matches if either the left, right or both versions of the key are pressed. /// Matches if either the left, right or both versions of the key are pressed.
any, any,
@ -45,10 +53,18 @@ enum KeyboardSide {
/// An enum describing the type of modifier key that is being pressed. /// An enum describing the type of modifier key that is being pressed.
/// ///
/// This enum is deprecated and will be removed. There is no direct substitute
/// planned, since this enum will no longer be necessary once [RawKeyEvent] and
/// associated APIs are removed.
///
/// See also: /// See also:
/// ///
/// * [RawKeyEventData.isModifierPressed], which accepts this enum as an /// * [RawKeyEventData.isModifierPressed], which accepts this enum as an
/// argument. /// argument.
@Deprecated(
'No longer supported. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
enum ModifierKey { enum ModifierKey {
/// The CTRL modifier key. /// The CTRL modifier key.
/// ///
@ -106,6 +122,9 @@ enum ModifierKey {
/// Base class for platform-specific key event data. /// Base class for platform-specific key event data.
/// ///
/// This class is deprecated, and will be removed. Platform specific key event
/// data will no be longer available. See [KeyEvent] for what is available.
///
/// This base class exists to have a common type to use for each of the /// This base class exists to have a common type to use for each of the
/// target platform's key event data structures. /// target platform's key event data structures.
/// ///
@ -116,56 +135,112 @@ enum ModifierKey {
/// * [RawKeyDownEvent] and [RawKeyUpEvent], the classes that hold the /// * [RawKeyDownEvent] and [RawKeyUpEvent], the classes that hold the
/// reference to [RawKeyEventData] subclasses. /// reference to [RawKeyEventData] subclasses.
/// * [RawKeyboard], which uses these interfaces to expose key data. /// * [RawKeyboard], which uses these interfaces 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
abstract class RawKeyEventData with Diagnosticable { abstract class RawKeyEventData with Diagnosticable {
/// Abstract const constructor. This constructor enables subclasses to provide /// Abstract const constructor. This constructor enables subclasses to provide
/// const constructors so that they can be used in const expressions. /// const constructors so that they can be used in const expressions.
@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 RawKeyEventData(); const RawKeyEventData();
/// 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.
/// ///
/// This method is deprecated and will be removed. For equivalent information,
/// inspect [HardwareKeyboard.logicalKeysPressed] instead.
///
/// If [side] is specified, then this restricts its check to the specified /// If [side] is specified, then this restricts its check to the specified
/// side of the keyboard. Defaults to checking for the key being down on /// side of the keyboard. Defaults to checking for the key being down on
/// either side of the keyboard. If there is only one instance of the key on /// either side of the keyboard. If there is only one instance of the key on
/// the keyboard, then [side] is ignored. /// the keyboard, then [side] is ignored.
@Deprecated(
'No longer available. Inspect HardwareKeyboard.instance.logicalKeysPressed instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
bool isModifierPressed(ModifierKey key, { KeyboardSide side = KeyboardSide.any }); bool isModifierPressed(ModifierKey key, { KeyboardSide side = KeyboardSide.any });
/// 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.
/// ///
/// This method is deprecated and will be removed.
///
/// If the modifier key wasn't pressed at the time of this event, returns /// If the modifier key wasn't pressed at the time of this event, returns
/// null. If the given key only appears in one place on the keyboard, returns /// null. If the given key only appears in one place on the keyboard, returns
/// [KeyboardSide.all] if pressed. If the given platform does not specify /// [KeyboardSide.all] if pressed. If the given platform does not specify
/// the side, return [KeyboardSide.any]. /// the side, return [KeyboardSide.any].
@Deprecated(
'No longer available. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
KeyboardSide? getModifierSide(ModifierKey key); KeyboardSide? getModifierSide(ModifierKey key);
/// Returns true if a CTRL modifier key was pressed at the time of this event, /// Returns true if a CTRL modifier key was pressed at the time of this event,
/// regardless of which side of the keyboard it is on. /// regardless of which side of the keyboard it is on.
/// ///
/// This method is deprecated and will be removed. Use
/// [HardwareKeyboard.isControlPressed] instead.
///
/// Use [isModifierPressed] if you need to know which control key was pressed. /// Use [isModifierPressed] if you need to know which control key was pressed.
@Deprecated(
'Use HardwareKeyboard.instance.isControlPressed instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
bool get isControlPressed => isModifierPressed(ModifierKey.controlModifier); bool get isControlPressed => isModifierPressed(ModifierKey.controlModifier);
/// Returns true if a SHIFT modifier key was pressed at the time of this /// Returns true if a SHIFT modifier key was pressed at the time of this
/// event, regardless of which side of the keyboard it is on. /// event, regardless of which side of the keyboard it is on.
/// ///
/// This method is deprecated and will be removed. Use
/// [HardwareKeyboard.isShiftPressed] instead.
///
/// Use [isModifierPressed] if you need to know which shift key was pressed. /// Use [isModifierPressed] if you need to know which shift key was pressed.
@Deprecated(
'Use HardwareKeyboard.instance.isShiftPressed instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
bool get isShiftPressed => isModifierPressed(ModifierKey.shiftModifier); bool get isShiftPressed => isModifierPressed(ModifierKey.shiftModifier);
/// Returns true if a ALT modifier key was pressed at the time of this event, /// Returns true if a ALT modifier key was pressed at the time of this event,
/// regardless of which side of the keyboard it is on. /// regardless of which side of the keyboard it is on.
/// ///
/// This method is deprecated and will be removed. Use
/// [HardwareKeyboard.isAltPressed] instead.
///
/// Use [isModifierPressed] if you need to know which alt key was pressed. /// Use [isModifierPressed] if you need to know which alt key was pressed.
@Deprecated(
'Use HardwareKeyboard.instance.isAltPressed instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
bool get isAltPressed => isModifierPressed(ModifierKey.altModifier); bool get isAltPressed => isModifierPressed(ModifierKey.altModifier);
/// Returns true if a META modifier key was pressed at the time of this event, /// Returns true if a META modifier key was pressed at the time of this event,
/// regardless of which side of the keyboard it is on. /// regardless of which side of the keyboard it is on.
/// ///
/// This method is deprecated and will be removed. Use
/// [HardwareKeyboard.isMetaPressed] instead.
///
/// Use [isModifierPressed] if you need to know which meta key was pressed. /// Use [isModifierPressed] if you need to know which meta key was pressed.
@Deprecated(
'Use HardwareKeyboard.instance.isMetaPressed instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
bool get isMetaPressed => isModifierPressed(ModifierKey.metaModifier); bool get isMetaPressed => isModifierPressed(ModifierKey.metaModifier);
/// Returns a map of modifier keys that were pressed at the time of this /// Returns a map of modifier keys that were pressed at the time of this
/// event, and the keyboard side or sides that the key was on. /// event, and the keyboard side or sides that the key was on.
///
/// This method is deprecated and will be removed. For equivalent information,
/// inspect [HardwareKeyboard.logicalKeysPressed] instead.
@Deprecated(
'No longer available. Inspect HardwareKeyboard.instance.logicalKeysPressed instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
Map<ModifierKey, KeyboardSide> get modifiersPressed { Map<ModifierKey, KeyboardSide> get modifiersPressed {
final Map<ModifierKey, KeyboardSide> result = <ModifierKey, KeyboardSide>{}; final Map<ModifierKey, KeyboardSide> result = <ModifierKey, KeyboardSide>{};
for (final ModifierKey key in ModifierKey.values) { for (final ModifierKey key in ModifierKey.values) {
@ -254,6 +329,11 @@ abstract class RawKeyEventData with Diagnosticable {
/// Defines the interface for raw key events. /// Defines the interface for raw key events.
/// ///
/// This type of event has been deprecated, and will be removed at a future
/// date. Instead of using this, use the [KeyEvent] class instead, which means
/// you will use [Focus.onKeyEvent], [HardwareKeyboard] and [KeyboardListener]
/// to get these events instead of the raw key event equivalents.
///
/// Raw key events pass through as much information as possible from the /// Raw key events pass through as much information as possible from the
/// underlying platform's key events, which allows them to provide a high level /// underlying platform's key events, which allows them to provide a high level
/// of fidelity but a low level of portability. /// of fidelity but a low level of portability.
@ -265,20 +345,28 @@ abstract class RawKeyEventData with Diagnosticable {
/// ///
/// See also: /// See also:
/// ///
/// * [LogicalKeyboardKey], an object that describes the logical meaning of a /// * [LogicalKeyboardKey], an object that describes the logical meaning of a
/// key. /// key.
/// * [PhysicalKeyboardKey], an object that describes the physical location of /// * [PhysicalKeyboardKey], an object that describes the physical location of a
/// a key. /// key.
/// * [RawKeyDownEvent], a specialization for events representing the user /// * [RawKeyDownEvent], a specialization for events representing the user
/// pressing a key. /// pressing a key.
/// * [RawKeyUpEvent], a specialization for events representing the user /// * [RawKeyUpEvent], a specialization for events representing the user
/// releasing a key. /// releasing a key.
/// * [RawKeyboard], which uses this interface to expose key data. /// * [RawKeyboard], which uses this interface to expose key data.
/// * [RawKeyboardListener], a widget that listens for raw key events. /// * [RawKeyboardListener], a widget that listens for raw key events.
@Deprecated(
'Use KeyEvent instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
@immutable @immutable
abstract class RawKeyEvent with Diagnosticable { abstract class RawKeyEvent with Diagnosticable {
/// Abstract const constructor. This constructor enables subclasses to provide /// Abstract const constructor. This constructor enables subclasses to provide
/// const constructors so that they can be used in const expressions. /// const constructors so that they can be used in const expressions.
@Deprecated(
'Use KeyEvent instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
const RawKeyEvent({ const RawKeyEvent({
required this.data, required this.data,
this.character, this.character,
@ -290,6 +378,10 @@ abstract class RawKeyEvent with Diagnosticable {
/// ///
/// [RawKeyEvent.repeat] will be derived from the current keyboard state, /// [RawKeyEvent.repeat] will be derived from the current keyboard state,
/// instead of using the message information. /// instead of using the message information.
@Deprecated(
'No longer supported. Use KeyEvent instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
factory RawKeyEvent.fromMessage(Map<String, Object?> message) { factory RawKeyEvent.fromMessage(Map<String, Object?> message) {
String? character; String? character;
RawKeyEventData dataFromWeb() { RawKeyEventData dataFromWeb() {
@ -407,12 +499,26 @@ abstract class RawKeyEvent with Diagnosticable {
} }
/// Returns true if the given [LogicalKeyboardKey] is pressed. /// Returns true if the given [LogicalKeyboardKey] is pressed.
///
/// This method is deprecated and will be removed. Use
/// [HardwareKeyboard.isLogicalKeyPressed] instead.
@Deprecated(
'Use HardwareKeyboard.instance.isLogicalKeyPressed instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
bool isKeyPressed(LogicalKeyboardKey key) => RawKeyboard.instance.keysPressed.contains(key); bool isKeyPressed(LogicalKeyboardKey key) => RawKeyboard.instance.keysPressed.contains(key);
/// Returns true if a CTRL modifier key is pressed, regardless of which side /// Returns true if a CTRL modifier key is pressed, regardless of which side
/// of the keyboard it is on. /// of the keyboard it is on.
/// ///
/// This method is deprecated and will be removed. Use
/// [HardwareKeyboard.isControlPressed] instead.
///
/// Use [isKeyPressed] if you need to know which control key was pressed. /// Use [isKeyPressed] if you need to know which control key was pressed.
@Deprecated(
'Use HardwareKeyboard.instance.isControlPressed instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
bool get isControlPressed { bool get isControlPressed {
return isKeyPressed(LogicalKeyboardKey.controlLeft) || isKeyPressed(LogicalKeyboardKey.controlRight); return isKeyPressed(LogicalKeyboardKey.controlLeft) || isKeyPressed(LogicalKeyboardKey.controlRight);
} }
@ -420,7 +526,14 @@ abstract class RawKeyEvent with Diagnosticable {
/// Returns true if a SHIFT modifier key is pressed, regardless of which side /// Returns true if a SHIFT modifier key is pressed, regardless of which side
/// of the keyboard it is on. /// of the keyboard it is on.
/// ///
/// This method is deprecated and will be removed. Use
/// [HardwareKeyboard.isShiftPressed] instead.
///
/// Use [isKeyPressed] if you need to know which shift key was pressed. /// Use [isKeyPressed] if you need to know which shift key was pressed.
@Deprecated(
'Use HardwareKeyboard.instance.isShiftPressed instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
bool get isShiftPressed { bool get isShiftPressed {
return isKeyPressed(LogicalKeyboardKey.shiftLeft) || isKeyPressed(LogicalKeyboardKey.shiftRight); return isKeyPressed(LogicalKeyboardKey.shiftLeft) || isKeyPressed(LogicalKeyboardKey.shiftRight);
} }
@ -428,6 +541,9 @@ abstract class RawKeyEvent with Diagnosticable {
/// Returns true if a ALT modifier key is pressed, regardless of which side /// Returns true if a ALT modifier key is pressed, regardless of which side
/// of the keyboard it is on. /// of the keyboard it is on.
/// ///
/// This method is deprecated and will be removed. Use
/// [HardwareKeyboard.isAltPressed] instead.
///
/// The `AltGr` key that appears on some keyboards is considered to be /// The `AltGr` key that appears on some keyboards is considered to be
/// the same as [LogicalKeyboardKey.altRight] on some platforms (notably /// the same as [LogicalKeyboardKey.altRight] on some platforms (notably
/// Android). On platforms that can distinguish between `altRight` and /// Android). On platforms that can distinguish between `altRight` and
@ -435,6 +551,10 @@ abstract class RawKeyEvent with Diagnosticable {
/// tested for separately. /// tested for separately.
/// ///
/// Use [isKeyPressed] if you need to know which alt key was pressed. /// Use [isKeyPressed] if you need to know which alt key was pressed.
@Deprecated(
'Use HardwareKeyboard.instance.isAltPressed instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
bool get isAltPressed { bool get isAltPressed {
return isKeyPressed(LogicalKeyboardKey.altLeft) || isKeyPressed(LogicalKeyboardKey.altRight); return isKeyPressed(LogicalKeyboardKey.altLeft) || isKeyPressed(LogicalKeyboardKey.altRight);
} }
@ -442,7 +562,14 @@ abstract class RawKeyEvent with Diagnosticable {
/// Returns true if a META modifier key is pressed, regardless of which side /// Returns true if a META modifier key is pressed, regardless of which side
/// of the keyboard it is on. /// of the keyboard it is on.
/// ///
/// This method is deprecated and will be removed. Use
/// [HardwareKeyboard.isMetaPressed] instead.
///
/// Use [isKeyPressed] if you need to know which meta key was pressed. /// Use [isKeyPressed] if you need to know which meta key was pressed.
@Deprecated(
'Use HardwareKeyboard.instance.isMetaPressed instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
bool get isMetaPressed { bool get isMetaPressed {
return isKeyPressed(LogicalKeyboardKey.metaLeft) || isKeyPressed(LogicalKeyboardKey.metaRight); return isKeyPressed(LogicalKeyboardKey.metaLeft) || isKeyPressed(LogicalKeyboardKey.metaRight);
} }
@ -536,11 +663,22 @@ abstract class RawKeyEvent with Diagnosticable {
/// The user has pressed a key on the keyboard. /// The user has pressed a key on the keyboard.
/// ///
/// This class has been deprecated and will be removed. Use [KeyDownEvent]
/// instead.
///
/// See also: /// See also:
/// ///
/// * [RawKeyboard], which uses this interface to expose key data. /// * [RawKeyboard], which uses this interface to expose key data.
@Deprecated(
'Use KeyDownEvent instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
class RawKeyDownEvent extends RawKeyEvent { class RawKeyDownEvent extends RawKeyEvent {
/// Creates a key event that represents the user pressing a key. /// Creates a key event that represents the user pressing a key.
@Deprecated(
'Use KeyDownEvent instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
const RawKeyDownEvent({ const RawKeyDownEvent({
required super.data, required super.data,
super.character, super.character,
@ -550,11 +688,22 @@ class RawKeyDownEvent extends RawKeyEvent {
/// The user has released a key on the keyboard. /// The user has released a key on the keyboard.
/// ///
/// This class has been deprecated and will be removed. Use [KeyUpEvent]
/// instead.
///
/// See also: /// See also:
/// ///
/// * [RawKeyboard], which uses this interface to expose key data. /// * [RawKeyboard], which uses this interface to expose key data.
@Deprecated(
'Use KeyUpEvent instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
class RawKeyUpEvent extends RawKeyEvent { class RawKeyUpEvent extends RawKeyEvent {
/// Creates a key event that represents the user releasing a key. /// Creates a key event that represents the user releasing a key.
@Deprecated(
'Use KeyUpEvent instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
const RawKeyUpEvent({ const RawKeyUpEvent({
required super.data, required super.data,
super.character, super.character,
@ -564,12 +713,22 @@ class RawKeyUpEvent extends RawKeyEvent {
/// A callback type used by [RawKeyboard.keyEventHandler] to send key events to /// A callback type used by [RawKeyboard.keyEventHandler] to send key events to
/// a handler that can determine if the key has been handled or not. /// a handler that can determine if the key has been handled or not.
/// ///
/// This typedef has been deprecated and will be removed. Use [KeyEventCallback]
/// instead.
///
/// The handler should return true if the key has been handled, and false if the /// The handler should return true if the key has been handled, and false if the
/// key was not handled. It must not return null. /// key was not handled. It must not return null.
@Deprecated(
'Use KeyEventCallback instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
typedef RawKeyEventHandler = bool Function(RawKeyEvent event); typedef RawKeyEventHandler = bool Function(RawKeyEvent event);
/// An interface for listening to raw key events. /// An interface for listening to raw key events.
/// ///
/// This class is deprecated and will be removed at a future date. The
/// [HardwareKeyboard] class is its replacement.
///
/// Raw key events pass through as much information as possible from the /// Raw key events pass through as much information as possible from the
/// underlying platform's key events, which makes them provide a high level of /// underlying platform's key events, which makes them provide a high level of
/// fidelity but a low level of portability. /// fidelity but a low level of portability.
@ -583,34 +742,42 @@ typedef RawKeyEventHandler = bool Function(RawKeyEvent event);
/// ///
/// ## Compared to [HardwareKeyboard] /// ## Compared to [HardwareKeyboard]
/// ///
/// [RawKeyboard] is the legacy API, and will be deprecated and removed in the /// Behavior-wise, [RawKeyboard] provides a less unified, less regular event
/// future. It is recommended to always use [HardwareKeyboard] and [KeyEvent] /// model than [HardwareKeyboard]. For example:
/// APIs (such as [FocusNode.onKeyEvent]) to handle key events.
/// ///
/// Behavior-wise, [RawKeyboard] provides a less unified, less regular /// * Down events might not be matched with an up event, and vice versa (the set
/// event model than [HardwareKeyboard]. For example: /// of pressed keys is silently updated).
/// /// * The logical key of the down event might not be the same as that of the up
/// * Down events might not be matched with an up event, and vice versa (the /// event.
/// set of pressed keys is silently updated). /// * Down events and repeat events are not easily distinguishable (must be
/// * The logical key of the down event might not be the same as that of the up /// tracked manually).
/// event. /// * Lock modes (such as CapsLock) only have their "enabled" state recorded.
/// * Down events and repeat events are not easily distinguishable (must be /// There's no way to acquire their pressing state.
/// tracked manually).
/// * Lock modes (such as CapsLock) only have their "enabled" state recorded.
/// There's no way to acquire their pressing state.
/// ///
/// See also: /// See also:
/// ///
/// * [RawKeyDownEvent] and [RawKeyUpEvent], the classes used to describe /// * [RawKeyDownEvent] and [RawKeyUpEvent], the classes used to describe
/// specific raw key events. /// specific raw key events.
/// * [RawKeyboardListener], a widget that listens for raw key events. /// * [RawKeyboardListener], a widget that listens for raw key events.
/// * [SystemChannels.keyEvent], the low-level channel used for receiving /// * [SystemChannels.keyEvent], the low-level channel used for receiving events
/// events from the system. /// from the system.
/// * [HardwareKeyboard], the recommended replacement. /// * [HardwareKeyboard], the recommended replacement.
@Deprecated(
'Use HardwareKeyboard instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
class RawKeyboard { class RawKeyboard {
@Deprecated(
'Use HardwareKeyboard instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
RawKeyboard._(); RawKeyboard._();
/// The shared instance of [RawKeyboard]. /// The shared instance of [RawKeyboard].
@Deprecated(
'Use HardwareKeyboard.instance instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
static final RawKeyboard instance = RawKeyboard._(); static final RawKeyboard instance = RawKeyboard._();
final List<ValueChanged<RawKeyEvent>> _listeners = <ValueChanged<RawKeyEvent>>[]; final List<ValueChanged<RawKeyEvent>> _listeners = <ValueChanged<RawKeyEvent>>[];

View File

@ -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;
/// 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,

View File

@ -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,

View File

@ -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 = '',

View File

@ -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 {
/// 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 {
/// 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 {
} }
/// 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 {
} }
/// 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.

View File

@ -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) {
/// 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 = '',

View File

@ -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) {
/// 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,

View File

@ -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;
/// 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,

View File

@ -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 {
/// {@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 {
/// ///
/// 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 {
/// 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 {
/// 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 {
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 {
/// 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 {
/// 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 {
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 {
} }
// 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,

View File

@ -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 {
/// 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 {
/// 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;

View File

@ -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.
/// ///

View File

@ -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;
/// 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,

View File

@ -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
/// 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
/// 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
/// ///
/// 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

View File

@ -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() {
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 {

View File

@ -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() {
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() {
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() {
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() {
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() {
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() {
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() {
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() {
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() {
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() {
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() {
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() {
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()
); );

View File

@ -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() {
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() {
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() {
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() {
)), 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() {
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() {
// 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 {

View File

@ -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() {
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', () {

View File

@ -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', () {

View File

@ -445,6 +445,7 @@ void main() {
debugDefaultTargetPlatformOverride = null; debugDefaultTargetPlatformOverride = null;
}, },
// ignore: deprecated_member_use
variant: KeySimulatorTransitModeVariant.all(), variant: KeySimulatorTransitModeVariant.all(),
); );

View File

@ -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 {

View File

@ -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() {
// 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() {
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() {
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 {

View File

@ -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() {
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() {
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() {
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() {
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() {
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() {
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 {

View File

@ -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() {
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() {
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() {
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() {
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() {
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() {
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 {

View File

@ -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() {
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() {
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() {
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() {
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() {
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() {
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() {
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() {
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() {
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 {

View File

@ -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() {
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() {
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() {
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() {
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() {
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() {
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 {

View File

@ -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();

View File

@ -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 {
/// 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 {
/// 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 {
/// 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.

View File

@ -309,6 +309,7 @@ abstract final class KeyEventSimulator {
static int _getAndroidModifierFlags(LogicalKeyboardKey newKey, bool isDown) { static int _getAndroidModifierFlags(LogicalKeyboardKey newKey, bool isDown) {
int result = 0; int result = 0;
// ignore: deprecated_member_use
final Set<LogicalKeyboardKey> pressed = RawKeyboard.instance.keysPressed; final Set<LogicalKeyboardKey> pressed = RawKeyboard.instance.keysPressed;
if (isDown) { if (isDown) {
pressed.add(newKey); pressed.add(newKey);
@ -316,39 +317,51 @@ abstract final class KeyEventSimulator {
pressed.remove(newKey); pressed.remove(newKey);
} }
if (pressed.contains(LogicalKeyboardKey.shiftLeft)) { if (pressed.contains(LogicalKeyboardKey.shiftLeft)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataAndroid.modifierLeftShift | RawKeyEventDataAndroid.modifierShift; result |= RawKeyEventDataAndroid.modifierLeftShift | RawKeyEventDataAndroid.modifierShift;
} }
if (pressed.contains(LogicalKeyboardKey.shiftRight)) { if (pressed.contains(LogicalKeyboardKey.shiftRight)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataAndroid.modifierRightShift | RawKeyEventDataAndroid.modifierShift; result |= RawKeyEventDataAndroid.modifierRightShift | RawKeyEventDataAndroid.modifierShift;
} }
if (pressed.contains(LogicalKeyboardKey.metaLeft)) { if (pressed.contains(LogicalKeyboardKey.metaLeft)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataAndroid.modifierLeftMeta | RawKeyEventDataAndroid.modifierMeta; result |= RawKeyEventDataAndroid.modifierLeftMeta | RawKeyEventDataAndroid.modifierMeta;
} }
if (pressed.contains(LogicalKeyboardKey.metaRight)) { if (pressed.contains(LogicalKeyboardKey.metaRight)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataAndroid.modifierRightMeta | RawKeyEventDataAndroid.modifierMeta; result |= RawKeyEventDataAndroid.modifierRightMeta | RawKeyEventDataAndroid.modifierMeta;
} }
if (pressed.contains(LogicalKeyboardKey.controlLeft)) { if (pressed.contains(LogicalKeyboardKey.controlLeft)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataAndroid.modifierLeftControl | RawKeyEventDataAndroid.modifierControl; result |= RawKeyEventDataAndroid.modifierLeftControl | RawKeyEventDataAndroid.modifierControl;
} }
if (pressed.contains(LogicalKeyboardKey.controlRight)) { if (pressed.contains(LogicalKeyboardKey.controlRight)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataAndroid.modifierRightControl | RawKeyEventDataAndroid.modifierControl; result |= RawKeyEventDataAndroid.modifierRightControl | RawKeyEventDataAndroid.modifierControl;
} }
if (pressed.contains(LogicalKeyboardKey.altLeft)) { if (pressed.contains(LogicalKeyboardKey.altLeft)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataAndroid.modifierLeftAlt | RawKeyEventDataAndroid.modifierAlt; result |= RawKeyEventDataAndroid.modifierLeftAlt | RawKeyEventDataAndroid.modifierAlt;
} }
if (pressed.contains(LogicalKeyboardKey.altRight)) { if (pressed.contains(LogicalKeyboardKey.altRight)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataAndroid.modifierRightAlt | RawKeyEventDataAndroid.modifierAlt; result |= RawKeyEventDataAndroid.modifierRightAlt | RawKeyEventDataAndroid.modifierAlt;
} }
if (pressed.contains(LogicalKeyboardKey.fn)) { if (pressed.contains(LogicalKeyboardKey.fn)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataAndroid.modifierFunction; result |= RawKeyEventDataAndroid.modifierFunction;
} }
if (pressed.contains(LogicalKeyboardKey.scrollLock)) { if (pressed.contains(LogicalKeyboardKey.scrollLock)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataAndroid.modifierScrollLock; result |= RawKeyEventDataAndroid.modifierScrollLock;
} }
if (pressed.contains(LogicalKeyboardKey.numLock)) { if (pressed.contains(LogicalKeyboardKey.numLock)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataAndroid.modifierNumLock; result |= RawKeyEventDataAndroid.modifierNumLock;
} }
if (pressed.contains(LogicalKeyboardKey.capsLock)) { if (pressed.contains(LogicalKeyboardKey.capsLock)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataAndroid.modifierCapsLock; result |= RawKeyEventDataAndroid.modifierCapsLock;
} }
return result; return result;
@ -356,6 +369,7 @@ abstract final class KeyEventSimulator {
static int _getGlfwModifierFlags(LogicalKeyboardKey newKey, bool isDown) { static int _getGlfwModifierFlags(LogicalKeyboardKey newKey, bool isDown) {
int result = 0; int result = 0;
// ignore: deprecated_member_use
final Set<LogicalKeyboardKey> pressed = RawKeyboard.instance.keysPressed; final Set<LogicalKeyboardKey> pressed = RawKeyboard.instance.keysPressed;
if (isDown) { if (isDown) {
pressed.add(newKey); pressed.add(newKey);
@ -363,18 +377,23 @@ abstract final class KeyEventSimulator {
pressed.remove(newKey); pressed.remove(newKey);
} }
if (pressed.contains(LogicalKeyboardKey.shiftLeft) || pressed.contains(LogicalKeyboardKey.shiftRight)) { if (pressed.contains(LogicalKeyboardKey.shiftLeft) || pressed.contains(LogicalKeyboardKey.shiftRight)) {
// ignore: deprecated_member_use
result |= GLFWKeyHelper.modifierShift; result |= GLFWKeyHelper.modifierShift;
} }
if (pressed.contains(LogicalKeyboardKey.metaLeft) || pressed.contains(LogicalKeyboardKey.metaRight)) { if (pressed.contains(LogicalKeyboardKey.metaLeft) || pressed.contains(LogicalKeyboardKey.metaRight)) {
// ignore: deprecated_member_use
result |= GLFWKeyHelper.modifierMeta; result |= GLFWKeyHelper.modifierMeta;
} }
if (pressed.contains(LogicalKeyboardKey.controlLeft) || pressed.contains(LogicalKeyboardKey.controlRight)) { if (pressed.contains(LogicalKeyboardKey.controlLeft) || pressed.contains(LogicalKeyboardKey.controlRight)) {
// ignore: deprecated_member_use
result |= GLFWKeyHelper.modifierControl; result |= GLFWKeyHelper.modifierControl;
} }
if (pressed.contains(LogicalKeyboardKey.altLeft) || pressed.contains(LogicalKeyboardKey.altRight)) { if (pressed.contains(LogicalKeyboardKey.altLeft) || pressed.contains(LogicalKeyboardKey.altRight)) {
// ignore: deprecated_member_use
result |= GLFWKeyHelper.modifierAlt; result |= GLFWKeyHelper.modifierAlt;
} }
if (pressed.contains(LogicalKeyboardKey.capsLock)) { if (pressed.contains(LogicalKeyboardKey.capsLock)) {
// ignore: deprecated_member_use
result |= GLFWKeyHelper.modifierCapsLock; result |= GLFWKeyHelper.modifierCapsLock;
} }
return result; return result;
@ -382,6 +401,7 @@ abstract final class KeyEventSimulator {
static int _getWindowsModifierFlags(LogicalKeyboardKey newKey, bool isDown) { static int _getWindowsModifierFlags(LogicalKeyboardKey newKey, bool isDown) {
int result = 0; int result = 0;
// ignore: deprecated_member_use
final Set<LogicalKeyboardKey> pressed = RawKeyboard.instance.keysPressed; final Set<LogicalKeyboardKey> pressed = RawKeyboard.instance.keysPressed;
if (isDown) { if (isDown) {
pressed.add(newKey); pressed.add(newKey);
@ -389,45 +409,59 @@ abstract final class KeyEventSimulator {
pressed.remove(newKey); pressed.remove(newKey);
} }
if (pressed.contains(LogicalKeyboardKey.shift)) { if (pressed.contains(LogicalKeyboardKey.shift)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataWindows.modifierShift; result |= RawKeyEventDataWindows.modifierShift;
} }
if (pressed.contains(LogicalKeyboardKey.shiftLeft)) { if (pressed.contains(LogicalKeyboardKey.shiftLeft)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataWindows.modifierLeftShift; result |= RawKeyEventDataWindows.modifierLeftShift;
} }
if (pressed.contains(LogicalKeyboardKey.shiftRight)) { if (pressed.contains(LogicalKeyboardKey.shiftRight)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataWindows.modifierRightShift; result |= RawKeyEventDataWindows.modifierRightShift;
} }
if (pressed.contains(LogicalKeyboardKey.metaLeft)) { if (pressed.contains(LogicalKeyboardKey.metaLeft)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataWindows.modifierLeftMeta; result |= RawKeyEventDataWindows.modifierLeftMeta;
} }
if (pressed.contains(LogicalKeyboardKey.metaRight)) { if (pressed.contains(LogicalKeyboardKey.metaRight)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataWindows.modifierRightMeta; result |= RawKeyEventDataWindows.modifierRightMeta;
} }
if (pressed.contains(LogicalKeyboardKey.control)) { if (pressed.contains(LogicalKeyboardKey.control)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataWindows.modifierControl; result |= RawKeyEventDataWindows.modifierControl;
} }
if (pressed.contains(LogicalKeyboardKey.controlLeft)) { if (pressed.contains(LogicalKeyboardKey.controlLeft)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataWindows.modifierLeftControl; result |= RawKeyEventDataWindows.modifierLeftControl;
} }
if (pressed.contains(LogicalKeyboardKey.controlRight)) { if (pressed.contains(LogicalKeyboardKey.controlRight)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataWindows.modifierRightControl; result |= RawKeyEventDataWindows.modifierRightControl;
} }
if (pressed.contains(LogicalKeyboardKey.alt)) { if (pressed.contains(LogicalKeyboardKey.alt)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataWindows.modifierAlt; result |= RawKeyEventDataWindows.modifierAlt;
} }
if (pressed.contains(LogicalKeyboardKey.altLeft)) { if (pressed.contains(LogicalKeyboardKey.altLeft)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataWindows.modifierLeftAlt; result |= RawKeyEventDataWindows.modifierLeftAlt;
} }
if (pressed.contains(LogicalKeyboardKey.altRight)) { if (pressed.contains(LogicalKeyboardKey.altRight)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataWindows.modifierRightAlt; result |= RawKeyEventDataWindows.modifierRightAlt;
} }
if (pressed.contains(LogicalKeyboardKey.capsLock)) { if (pressed.contains(LogicalKeyboardKey.capsLock)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataWindows.modifierCaps; result |= RawKeyEventDataWindows.modifierCaps;
} }
if (pressed.contains(LogicalKeyboardKey.numLock)) { if (pressed.contains(LogicalKeyboardKey.numLock)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataWindows.modifierNumLock; result |= RawKeyEventDataWindows.modifierNumLock;
} }
if (pressed.contains(LogicalKeyboardKey.scrollLock)) { if (pressed.contains(LogicalKeyboardKey.scrollLock)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataWindows.modifierScrollLock; result |= RawKeyEventDataWindows.modifierScrollLock;
} }
return result; return result;
@ -435,6 +469,7 @@ abstract final class KeyEventSimulator {
static int _getFuchsiaModifierFlags(LogicalKeyboardKey newKey, bool isDown) { static int _getFuchsiaModifierFlags(LogicalKeyboardKey newKey, bool isDown) {
int result = 0; int result = 0;
// ignore: deprecated_member_use
final Set<LogicalKeyboardKey> pressed = RawKeyboard.instance.keysPressed; final Set<LogicalKeyboardKey> pressed = RawKeyboard.instance.keysPressed;
if (isDown) { if (isDown) {
pressed.add(newKey); pressed.add(newKey);
@ -442,30 +477,39 @@ abstract final class KeyEventSimulator {
pressed.remove(newKey); pressed.remove(newKey);
} }
if (pressed.contains(LogicalKeyboardKey.shiftLeft)) { if (pressed.contains(LogicalKeyboardKey.shiftLeft)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataFuchsia.modifierLeftShift; result |= RawKeyEventDataFuchsia.modifierLeftShift;
} }
if (pressed.contains(LogicalKeyboardKey.shiftRight)) { if (pressed.contains(LogicalKeyboardKey.shiftRight)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataFuchsia.modifierRightShift; result |= RawKeyEventDataFuchsia.modifierRightShift;
} }
if (pressed.contains(LogicalKeyboardKey.metaLeft)) { if (pressed.contains(LogicalKeyboardKey.metaLeft)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataFuchsia.modifierLeftMeta; result |= RawKeyEventDataFuchsia.modifierLeftMeta;
} }
if (pressed.contains(LogicalKeyboardKey.metaRight)) { if (pressed.contains(LogicalKeyboardKey.metaRight)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataFuchsia.modifierRightMeta; result |= RawKeyEventDataFuchsia.modifierRightMeta;
} }
if (pressed.contains(LogicalKeyboardKey.controlLeft)) { if (pressed.contains(LogicalKeyboardKey.controlLeft)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataFuchsia.modifierLeftControl; result |= RawKeyEventDataFuchsia.modifierLeftControl;
} }
if (pressed.contains(LogicalKeyboardKey.controlRight)) { if (pressed.contains(LogicalKeyboardKey.controlRight)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataFuchsia.modifierRightControl; result |= RawKeyEventDataFuchsia.modifierRightControl;
} }
if (pressed.contains(LogicalKeyboardKey.altLeft)) { if (pressed.contains(LogicalKeyboardKey.altLeft)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataFuchsia.modifierLeftAlt; result |= RawKeyEventDataFuchsia.modifierLeftAlt;
} }
if (pressed.contains(LogicalKeyboardKey.altRight)) { if (pressed.contains(LogicalKeyboardKey.altRight)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataFuchsia.modifierRightAlt; result |= RawKeyEventDataFuchsia.modifierRightAlt;
} }
if (pressed.contains(LogicalKeyboardKey.capsLock)) { if (pressed.contains(LogicalKeyboardKey.capsLock)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataFuchsia.modifierCapsLock; result |= RawKeyEventDataFuchsia.modifierCapsLock;
} }
return result; return result;
@ -473,6 +517,7 @@ abstract final class KeyEventSimulator {
static int _getWebModifierFlags(LogicalKeyboardKey newKey, bool isDown) { static int _getWebModifierFlags(LogicalKeyboardKey newKey, bool isDown) {
int result = 0; int result = 0;
// ignore: deprecated_member_use
final Set<LogicalKeyboardKey> pressed = RawKeyboard.instance.keysPressed; final Set<LogicalKeyboardKey> pressed = RawKeyboard.instance.keysPressed;
if (isDown) { if (isDown) {
pressed.add(newKey); pressed.add(newKey);
@ -480,36 +525,47 @@ abstract final class KeyEventSimulator {
pressed.remove(newKey); pressed.remove(newKey);
} }
if (pressed.contains(LogicalKeyboardKey.shiftLeft)) { if (pressed.contains(LogicalKeyboardKey.shiftLeft)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataWeb.modifierShift; result |= RawKeyEventDataWeb.modifierShift;
} }
if (pressed.contains(LogicalKeyboardKey.shiftRight)) { if (pressed.contains(LogicalKeyboardKey.shiftRight)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataWeb.modifierShift; result |= RawKeyEventDataWeb.modifierShift;
} }
if (pressed.contains(LogicalKeyboardKey.metaLeft)) { if (pressed.contains(LogicalKeyboardKey.metaLeft)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataWeb.modifierMeta; result |= RawKeyEventDataWeb.modifierMeta;
} }
if (pressed.contains(LogicalKeyboardKey.metaRight)) { if (pressed.contains(LogicalKeyboardKey.metaRight)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataWeb.modifierMeta; result |= RawKeyEventDataWeb.modifierMeta;
} }
if (pressed.contains(LogicalKeyboardKey.controlLeft)) { if (pressed.contains(LogicalKeyboardKey.controlLeft)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataWeb.modifierControl; result |= RawKeyEventDataWeb.modifierControl;
} }
if (pressed.contains(LogicalKeyboardKey.controlRight)) { if (pressed.contains(LogicalKeyboardKey.controlRight)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataWeb.modifierControl; result |= RawKeyEventDataWeb.modifierControl;
} }
if (pressed.contains(LogicalKeyboardKey.altLeft)) { if (pressed.contains(LogicalKeyboardKey.altLeft)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataWeb.modifierAlt; result |= RawKeyEventDataWeb.modifierAlt;
} }
if (pressed.contains(LogicalKeyboardKey.altRight)) { if (pressed.contains(LogicalKeyboardKey.altRight)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataWeb.modifierAlt; result |= RawKeyEventDataWeb.modifierAlt;
} }
if (pressed.contains(LogicalKeyboardKey.capsLock)) { if (pressed.contains(LogicalKeyboardKey.capsLock)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataWeb.modifierCapsLock; result |= RawKeyEventDataWeb.modifierCapsLock;
} }
if (pressed.contains(LogicalKeyboardKey.numLock)) { if (pressed.contains(LogicalKeyboardKey.numLock)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataWeb.modifierNumLock; result |= RawKeyEventDataWeb.modifierNumLock;
} }
if (pressed.contains(LogicalKeyboardKey.scrollLock)) { if (pressed.contains(LogicalKeyboardKey.scrollLock)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataWeb.modifierScrollLock; result |= RawKeyEventDataWeb.modifierScrollLock;
} }
return result; return result;
@ -517,6 +573,7 @@ abstract final class KeyEventSimulator {
static int _getMacOsModifierFlags(LogicalKeyboardKey newKey, bool isDown) { static int _getMacOsModifierFlags(LogicalKeyboardKey newKey, bool isDown) {
int result = 0; int result = 0;
// ignore: deprecated_member_use
final Set<LogicalKeyboardKey> pressed = RawKeyboard.instance.keysPressed; final Set<LogicalKeyboardKey> pressed = RawKeyboard.instance.keysPressed;
if (isDown) { if (isDown) {
pressed.add(newKey); pressed.add(newKey);
@ -524,27 +581,35 @@ abstract final class KeyEventSimulator {
pressed.remove(newKey); pressed.remove(newKey);
} }
if (pressed.contains(LogicalKeyboardKey.shiftLeft)) { if (pressed.contains(LogicalKeyboardKey.shiftLeft)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataMacOs.modifierLeftShift | RawKeyEventDataMacOs.modifierShift; result |= RawKeyEventDataMacOs.modifierLeftShift | RawKeyEventDataMacOs.modifierShift;
} }
if (pressed.contains(LogicalKeyboardKey.shiftRight)) { if (pressed.contains(LogicalKeyboardKey.shiftRight)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataMacOs.modifierRightShift | RawKeyEventDataMacOs.modifierShift; result |= RawKeyEventDataMacOs.modifierRightShift | RawKeyEventDataMacOs.modifierShift;
} }
if (pressed.contains(LogicalKeyboardKey.metaLeft)) { if (pressed.contains(LogicalKeyboardKey.metaLeft)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataMacOs.modifierLeftCommand | RawKeyEventDataMacOs.modifierCommand; result |= RawKeyEventDataMacOs.modifierLeftCommand | RawKeyEventDataMacOs.modifierCommand;
} }
if (pressed.contains(LogicalKeyboardKey.metaRight)) { if (pressed.contains(LogicalKeyboardKey.metaRight)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataMacOs.modifierRightCommand | RawKeyEventDataMacOs.modifierCommand; result |= RawKeyEventDataMacOs.modifierRightCommand | RawKeyEventDataMacOs.modifierCommand;
} }
if (pressed.contains(LogicalKeyboardKey.controlLeft)) { if (pressed.contains(LogicalKeyboardKey.controlLeft)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataMacOs.modifierLeftControl | RawKeyEventDataMacOs.modifierControl; result |= RawKeyEventDataMacOs.modifierLeftControl | RawKeyEventDataMacOs.modifierControl;
} }
if (pressed.contains(LogicalKeyboardKey.controlRight)) { if (pressed.contains(LogicalKeyboardKey.controlRight)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataMacOs.modifierRightControl | RawKeyEventDataMacOs.modifierControl; result |= RawKeyEventDataMacOs.modifierRightControl | RawKeyEventDataMacOs.modifierControl;
} }
if (pressed.contains(LogicalKeyboardKey.altLeft)) { if (pressed.contains(LogicalKeyboardKey.altLeft)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataMacOs.modifierLeftOption | RawKeyEventDataMacOs.modifierOption; result |= RawKeyEventDataMacOs.modifierLeftOption | RawKeyEventDataMacOs.modifierOption;
} }
if (pressed.contains(LogicalKeyboardKey.altRight)) { if (pressed.contains(LogicalKeyboardKey.altRight)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataMacOs.modifierRightOption | RawKeyEventDataMacOs.modifierOption; result |= RawKeyEventDataMacOs.modifierRightOption | RawKeyEventDataMacOs.modifierOption;
} }
final Set<LogicalKeyboardKey> functionKeys = <LogicalKeyboardKey>{ final Set<LogicalKeyboardKey> functionKeys = <LogicalKeyboardKey>{
@ -571,12 +636,15 @@ abstract final class KeyEventSimulator {
LogicalKeyboardKey.f21, LogicalKeyboardKey.f21,
}; };
if (pressed.intersection(functionKeys).isNotEmpty) { if (pressed.intersection(functionKeys).isNotEmpty) {
// ignore: deprecated_member_use
result |= RawKeyEventDataMacOs.modifierFunction; result |= RawKeyEventDataMacOs.modifierFunction;
} }
if (pressed.intersection(kMacOsNumPadMap.values.toSet()).isNotEmpty) { if (pressed.intersection(kMacOsNumPadMap.values.toSet()).isNotEmpty) {
// ignore: deprecated_member_use
result |= RawKeyEventDataMacOs.modifierNumericPad; result |= RawKeyEventDataMacOs.modifierNumericPad;
} }
if (pressed.contains(LogicalKeyboardKey.capsLock)) { if (pressed.contains(LogicalKeyboardKey.capsLock)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataMacOs.modifierCapsLock; result |= RawKeyEventDataMacOs.modifierCapsLock;
} }
return result; return result;
@ -584,6 +652,7 @@ abstract final class KeyEventSimulator {
static int _getIOSModifierFlags(LogicalKeyboardKey newKey, bool isDown) { static int _getIOSModifierFlags(LogicalKeyboardKey newKey, bool isDown) {
int result = 0; int result = 0;
// ignore: deprecated_member_use
final Set<LogicalKeyboardKey> pressed = RawKeyboard.instance.keysPressed; final Set<LogicalKeyboardKey> pressed = RawKeyboard.instance.keysPressed;
if (isDown) { if (isDown) {
pressed.add(newKey); pressed.add(newKey);
@ -591,27 +660,35 @@ abstract final class KeyEventSimulator {
pressed.remove(newKey); pressed.remove(newKey);
} }
if (pressed.contains(LogicalKeyboardKey.shiftLeft)) { if (pressed.contains(LogicalKeyboardKey.shiftLeft)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataIos.modifierLeftShift | RawKeyEventDataIos.modifierShift; result |= RawKeyEventDataIos.modifierLeftShift | RawKeyEventDataIos.modifierShift;
} }
if (pressed.contains(LogicalKeyboardKey.shiftRight)) { if (pressed.contains(LogicalKeyboardKey.shiftRight)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataIos.modifierRightShift | RawKeyEventDataIos.modifierShift; result |= RawKeyEventDataIos.modifierRightShift | RawKeyEventDataIos.modifierShift;
} }
if (pressed.contains(LogicalKeyboardKey.metaLeft)) { if (pressed.contains(LogicalKeyboardKey.metaLeft)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataIos.modifierLeftCommand | RawKeyEventDataIos.modifierCommand; result |= RawKeyEventDataIos.modifierLeftCommand | RawKeyEventDataIos.modifierCommand;
} }
if (pressed.contains(LogicalKeyboardKey.metaRight)) { if (pressed.contains(LogicalKeyboardKey.metaRight)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataIos.modifierRightCommand | RawKeyEventDataIos.modifierCommand; result |= RawKeyEventDataIos.modifierRightCommand | RawKeyEventDataIos.modifierCommand;
} }
if (pressed.contains(LogicalKeyboardKey.controlLeft)) { if (pressed.contains(LogicalKeyboardKey.controlLeft)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataIos.modifierLeftControl | RawKeyEventDataIos.modifierControl; result |= RawKeyEventDataIos.modifierLeftControl | RawKeyEventDataIos.modifierControl;
} }
if (pressed.contains(LogicalKeyboardKey.controlRight)) { if (pressed.contains(LogicalKeyboardKey.controlRight)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataIos.modifierRightControl | RawKeyEventDataIos.modifierControl; result |= RawKeyEventDataIos.modifierRightControl | RawKeyEventDataIos.modifierControl;
} }
if (pressed.contains(LogicalKeyboardKey.altLeft)) { if (pressed.contains(LogicalKeyboardKey.altLeft)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataIos.modifierLeftOption | RawKeyEventDataIos.modifierOption; result |= RawKeyEventDataIos.modifierLeftOption | RawKeyEventDataIos.modifierOption;
} }
if (pressed.contains(LogicalKeyboardKey.altRight)) { if (pressed.contains(LogicalKeyboardKey.altRight)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataIos.modifierRightOption | RawKeyEventDataIos.modifierOption; result |= RawKeyEventDataIos.modifierRightOption | RawKeyEventDataIos.modifierOption;
} }
final Set<LogicalKeyboardKey> functionKeys = <LogicalKeyboardKey>{ final Set<LogicalKeyboardKey> functionKeys = <LogicalKeyboardKey>{
@ -638,12 +715,15 @@ abstract final class KeyEventSimulator {
LogicalKeyboardKey.f21, LogicalKeyboardKey.f21,
}; };
if (pressed.intersection(functionKeys).isNotEmpty) { if (pressed.intersection(functionKeys).isNotEmpty) {
// ignore: deprecated_member_use
result |= RawKeyEventDataIos.modifierFunction; result |= RawKeyEventDataIos.modifierFunction;
} }
if (pressed.intersection(kMacOsNumPadMap.values.toSet()).isNotEmpty) { if (pressed.intersection(kMacOsNumPadMap.values.toSet()).isNotEmpty) {
// ignore: deprecated_member_use
result |= RawKeyEventDataIos.modifierNumericPad; result |= RawKeyEventDataIos.modifierNumericPad;
} }
if (pressed.contains(LogicalKeyboardKey.capsLock)) { if (pressed.contains(LogicalKeyboardKey.capsLock)) {
// ignore: deprecated_member_use
result |= RawKeyEventDataIos.modifierCapsLock; result |= RawKeyEventDataIos.modifierCapsLock;
} }
return result; return result;
@ -684,6 +764,7 @@ abstract final class KeyEventSimulator {
return result!; return result!;
} }
// ignore: deprecated_member_use
static const KeyDataTransitMode _defaultTransitMode = KeyDataTransitMode.rawKeyData; static const KeyDataTransitMode _defaultTransitMode = KeyDataTransitMode.rawKeyData;
// The simulation transit mode for [simulateKeyDownEvent], [simulateKeyUpEvent], // The simulation transit mode for [simulateKeyDownEvent], [simulateKeyUpEvent],
@ -696,9 +777,12 @@ abstract final class KeyEventSimulator {
// The `_transitMode` defaults to [KeyDataTransitMode.rawKeyEvent], and can be // The `_transitMode` defaults to [KeyDataTransitMode.rawKeyEvent], and can be
// overridden with [debugKeyEventSimulatorTransitModeOverride]. In widget tests, it // overridden with [debugKeyEventSimulatorTransitModeOverride]. In widget tests, it
// is often set with [KeySimulationModeVariant]. // is often set with [KeySimulationModeVariant].
// ignore: deprecated_member_use
static KeyDataTransitMode get _transitMode { static KeyDataTransitMode get _transitMode {
// ignore: deprecated_member_use
KeyDataTransitMode? result; KeyDataTransitMode? result;
assert(() { assert(() {
// ignore: deprecated_member_use
result = debugKeyEventSimulatorTransitModeOverride; result = debugKeyEventSimulatorTransitModeOverride;
return true; return true;
}()); }());
@ -736,10 +820,13 @@ abstract final class KeyEventSimulator {
}); });
} }
switch (_transitMode) { switch (_transitMode) {
// ignore: deprecated_member_use
case KeyDataTransitMode.rawKeyData: case KeyDataTransitMode.rawKeyData:
return simulateByRawEvent(); return simulateByRawEvent();
// ignore: deprecated_member_use
case KeyDataTransitMode.keyDataThenRawKeyData: case KeyDataTransitMode.keyDataThenRawKeyData:
final LogicalKeyboardKey logicalKey = _getKeySynonym(key); final LogicalKeyboardKey logicalKey = _getKeySynonym(key);
// ignore: deprecated_member_use
final bool resultByKeyEvent = ServicesBinding.instance.keyEventManager.handleKeyData( final bool resultByKeyEvent = ServicesBinding.instance.keyEventManager.handleKeyData(
ui.KeyData( ui.KeyData(
type: ui.KeyEventType.down, type: ui.KeyEventType.down,
@ -780,10 +867,13 @@ abstract final class KeyEventSimulator {
}); });
} }
switch (_transitMode) { switch (_transitMode) {
// ignore: deprecated_member_use
case KeyDataTransitMode.rawKeyData: case KeyDataTransitMode.rawKeyData:
return simulateByRawEvent(); return simulateByRawEvent();
// ignore: deprecated_member_use
case KeyDataTransitMode.keyDataThenRawKeyData: case KeyDataTransitMode.keyDataThenRawKeyData:
final LogicalKeyboardKey logicalKey = _getKeySynonym(key); final LogicalKeyboardKey logicalKey = _getKeySynonym(key);
// ignore: deprecated_member_use
final bool resultByKeyEvent = ServicesBinding.instance.keyEventManager.handleKeyData( final bool resultByKeyEvent = ServicesBinding.instance.keyEventManager.handleKeyData(
ui.KeyData( ui.KeyData(
type: ui.KeyEventType.up, type: ui.KeyEventType.up,
@ -825,10 +915,13 @@ abstract final class KeyEventSimulator {
}); });
} }
switch (_transitMode) { switch (_transitMode) {
// ignore: deprecated_member_use
case KeyDataTransitMode.rawKeyData: case KeyDataTransitMode.rawKeyData:
return simulateByRawEvent(); return simulateByRawEvent();
// ignore: deprecated_member_use
case KeyDataTransitMode.keyDataThenRawKeyData: case KeyDataTransitMode.keyDataThenRawKeyData:
final LogicalKeyboardKey logicalKey = _getKeySynonym(key); final LogicalKeyboardKey logicalKey = _getKeySynonym(key);
// ignore: deprecated_member_use
final bool resultByKeyEvent = ServicesBinding.instance.keyEventManager.handleKeyData( final bool resultByKeyEvent = ServicesBinding.instance.keyEventManager.handleKeyData(
ui.KeyData( ui.KeyData(
type: ui.KeyEventType.repeat, type: ui.KeyEventType.repeat,
@ -935,17 +1028,33 @@ Future<bool> simulateKeyRepeatEvent(
/// A [TestVariant] that runs tests with transit modes set to different values /// A [TestVariant] that runs tests with transit modes set to different values
/// of [KeyDataTransitMode]. /// of [KeyDataTransitMode].
@Deprecated(
'No longer supported. Transit mode is always key data only. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
class KeySimulatorTransitModeVariant extends TestVariant<KeyDataTransitMode> { class KeySimulatorTransitModeVariant extends TestVariant<KeyDataTransitMode> {
/// Creates a [KeySimulatorTransitModeVariant] that tests the given [values]. /// Creates a [KeySimulatorTransitModeVariant] that tests the given [values].
@Deprecated(
'No longer supported. Transit mode is always key data only. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
const KeySimulatorTransitModeVariant(this.values); const KeySimulatorTransitModeVariant(this.values);
/// Creates a [KeySimulatorTransitModeVariant] for each value option of /// Creates a [KeySimulatorTransitModeVariant] for each value option of
/// [KeyDataTransitMode]. /// [KeyDataTransitMode].
@Deprecated(
'No longer supported. Transit mode is always key data only. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
KeySimulatorTransitModeVariant.all() KeySimulatorTransitModeVariant.all()
: this(KeyDataTransitMode.values.toSet()); : this(KeyDataTransitMode.values.toSet());
/// Creates a [KeySimulatorTransitModeVariant] that only contains /// Creates a [KeySimulatorTransitModeVariant] that only contains
/// [KeyDataTransitMode.keyDataThenRawKeyData]. /// [KeyDataTransitMode.keyDataThenRawKeyData].
@Deprecated(
'No longer supported. Transit mode is always key data only. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
KeySimulatorTransitModeVariant.keyDataThenRawKeyData() KeySimulatorTransitModeVariant.keyDataThenRawKeyData()
: this(<KeyDataTransitMode>{KeyDataTransitMode.keyDataThenRawKeyData}); : this(<KeyDataTransitMode>{KeyDataTransitMode.keyDataThenRawKeyData});

View File

@ -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 {
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() {
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() {
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() {
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() {
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() {
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() {
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() {
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() {
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() {
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;
}); });
} }