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/services.dart';
// TODO(gspencergoog): Delete this example when deprecated RawKeyEvent API is
// removed.
// ignore_for_file: deprecated_member_use
/// Flutter code sample for [KeyEventManager.keyMessageHandler].
void main() {

View File

@ -16,6 +16,7 @@ import 'debug.dart';
import 'hardware_keyboard.dart';
import 'message_codec.dart';
import 'platform_channel.dart';
import 'raw_keyboard.dart' show RawKeyboard;
import 'restoration.dart';
import 'service_extensions.dart';
import 'system_channels.dart';
@ -66,6 +67,13 @@ mixin ServicesBinding on BindingBase, SchedulerBinding {
/// The global singleton instance of [KeyEventManager], which is used
/// internally to dispatch key messages.
///
/// This property is deprecated, and will be removed. See
/// [HardwareKeyboard.addHandler] instead.
@Deprecated(
'No longer supported. Add a handler to HardwareKeyboard instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
KeyEventManager get keyEventManager => _keyEventManager;
late final KeyEventManager _keyEventManager;
@ -89,8 +97,8 @@ mixin ServicesBinding on BindingBase, SchedulerBinding {
BinaryMessenger get defaultBinaryMessenger => _defaultBinaryMessenger;
late final BinaryMessenger _defaultBinaryMessenger;
/// A token that represents the root isolate, used for coordinating with background
/// isolates.
/// A token that represents the root isolate, used for coordinating with
/// background isolates.
///
/// This property is primarily intended for use with
/// [BackgroundIsolateBinaryMessenger.ensureInitialized], which takes a

View File

@ -13,6 +13,12 @@ export 'hardware_keyboard.dart' show KeyDataTransitMode;
/// Setting [debugKeyEventSimulatorTransitModeOverride] is a good way to make
/// certain tests simulate the behavior of different type of platforms in terms
/// of their extent of support for keyboard API.
///
/// This value is deprecated and will be removed.
@Deprecated(
'No longer supported. Transit mode is always key data only. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
KeyDataTransitMode? debugKeyEventSimulatorTransitModeOverride;
/// Setting to true will cause extensive logging to occur when key events are

View File

@ -17,7 +17,6 @@ export 'dart:ui' show KeyData;
export 'package:flutter/foundation.dart' show DiagnosticPropertiesBuilder;
export 'keyboard_key.g.dart' show LogicalKeyboardKey, PhysicalKeyboardKey;
export 'raw_keyboard.dart' show RawKeyEvent, RawKeyboard;
// 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
/// 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:
///
/// * [KeyDownEvent], [KeyRepeatEvent], and [KeyUpEvent], the classes used to
/// describe specific key events.
/// * [instance], the singleton instance of this class.
/// * [RawKeyboard], the legacy API that dispatches key events containing raw
/// system data.
class HardwareKeyboard {
/// Provides convenient access to the current [HardwareKeyboard] singleton from
/// the [ServicesBinding] instance.
@ -701,6 +680,10 @@ class HardwareKeyboard {
/// 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
/// framework of native key events, which is called "transit mode".
///
@ -714,12 +697,16 @@ class HardwareKeyboard {
///
/// See also:
///
/// * [KeyEventManager], which infers the transit mode of the current platform
/// and guides how key messages are dispatched.
/// * [debugKeyEventSimulatorTransitModeOverride], overrides the transit mode
/// used to simulate key events.
/// * [KeySimulatorTransitModeVariant], an easier way to set
/// [debugKeyEventSimulatorTransitModeOverride] in widget tests.
/// * [KeyEventManager], which infers the transit mode of the current platform
/// and guides how key messages are dispatched.
/// * [debugKeyEventSimulatorTransitModeOverride], overrides the transit mode
/// used to simulate key events.
/// * [KeySimulatorTransitModeVariant], an easier way to set
/// [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 {
/// 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
/// 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,
/// 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
/// [KeyEventManager] will use the [ui.KeyData] for [KeyMessage.events], and
/// 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,
}
/// The assembled information converted from a native key message.
///
/// Native key messages, produced by physically pressing or releasing
/// keyboard keys, are translated into two different event streams in Flutter:
/// This class is deprecated, and will be removed. There is no direct substitute
/// planned, since this class will no longer be necessary once [RawKeyEvent] and
/// associated APIs are removed.
///
/// * The [KeyEvent] stream, represented by [KeyMessage.events] (recommended).
/// * The [RawKeyEvent] stream, represented by [KeyMessage.rawEvent] (legacy,
/// to be deprecated).
/// Native key messages, produced by physically pressing or releasing keyboard
/// keys, are translated into two different event streams in Flutter:
///
/// * 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
/// complete description of the keyboard messages, but in different event
/// models. Flutter is still transitioning from the legacy model to the new
/// model, therefore it dispatches both streams simultaneously until the
/// transition is completed. [KeyMessage] is used to bundle the
/// stream segments of both models from a native key message together for the
/// convenience of propagation.
/// transition is completed. [KeyMessage] is used to bundle the stream segments
/// of both models from a native key message together for the convenience of
/// propagation.
///
/// Typically, an application either processes [KeyMessage.events]
/// or [KeyMessage.rawEvent], not both. For example, handling a
/// [KeyMessage], means handling each event in [KeyMessage.events].
/// Typically, an application either processes [KeyMessage.events] or
/// [KeyMessage.rawEvent], not both. For example, handling a [KeyMessage], means
/// handling each event in [KeyMessage.events].
///
/// 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
/// an `onKeyEvent` that dispatches [KeyEvent]s. To processes a [KeyMessage],
/// it first calls `onKeyEvent` with each [KeyEvent] of [events], and then
/// `onKey` with [rawEvent]. All callbacks are invoked regardless of their
/// an `onKeyEvent` that dispatches [KeyEvent]s. To processes a [KeyMessage], it
/// first calls `onKeyEvent` with each [KeyEvent] of [events], and then `onKey`
/// with [rawEvent]. All callbacks are invoked regardless of their
/// [KeyEventResult]. Their results are combined into the result of the node
/// using [combineKeyEventResults].
///
/// ```dart
/// // ignore: deprecated_member_use
/// void handleMessage(FocusNode node, KeyMessage message) {
/// final List<KeyEventResult> results = <KeyEventResult>[];
/// if (node.onKeyEvent != null) {
@ -785,18 +785,28 @@ enum KeyDataTransitMode {
/// results.add(node.onKeyEvent!(node, event));
/// }
/// }
/// // ignore: deprecated_member_use
/// if (node.onKey != null && message.rawEvent != null) {
/// // ignore: deprecated_member_use
/// results.add(node.onKey!(node, message.rawEvent!));
/// }
/// final KeyEventResult result = combineKeyEventResults(results);
/// // 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
class KeyMessage {
/// Create a [KeyMessage] by providing all information.
///
/// 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);
/// The list of [KeyEvent]s converted from the native key message.
@ -838,34 +848,47 @@ class KeyMessage {
/// The signature for [KeyEventManager.keyMessageHandler].
///
/// A [KeyMessageHandler] processes a [KeyMessage] and returns whether
/// the message is considered handled. Handled messages should not be
/// propagated to other native components.
/// A [KeyMessageHandler] processes a [KeyMessage] and returns whether the
/// message is considered handled. Handled messages should not be propagated to
/// 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);
/// A singleton class that processes key messages from the platform and
/// dispatches converted messages accordingly.
///
/// [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.
/// This class is deprecated, and will be removed. There is no direct substitute
/// planned, since this class will no longer be necessary once [RawKeyEvent] and
/// associated APIs are removed.
///
/// [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
/// [ServicesBinding].
///
/// ## 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
/// "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
/// * The "hardware key event" pathway receives messages from the
/// "flutter/keydata" message channel (embedder API
/// `FlutterEngineSendKeyEvent`) and dispatches [KeyEvent] to
/// [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
/// 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
/// "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
/// considered a legacy platform. The raw key event is transformed into a
/// hardware key event at best effort. No messages from "flutter/keydata" are
/// expected.
/// * If a "flutter/keydata" message is received first, then this platform is
/// considered a newer platform. The hardware key events are stored, and
/// dispatched only when a raw key message is received.
/// expected. This behavior has been deprecated, and will be removed at a
/// future date.
///
/// Therefore, to correctly implement a platform that supports
/// `FlutterEngineSendKeyEvent`, the platform must ensure that
/// `FlutterEngineSendKeyEvent` is called before sending a message to
/// "flutter/keyevent" at the beginning of the app, and every physical key event
/// 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 {
/// Create an instance.
///
/// 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);
/// The global entrance which handles all key events sent to Flutter.
///
/// Typical applications use [WidgetsBinding], where this field is
/// set by the 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.
/// This handler is deprecated and will be removed. Use
/// [HardwareKeyboard.addHandler]/[HardwareKeyboard.removeHandler] instead.
///
/// Typical applications use [WidgetsBinding], where this field is set by the
/// 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 details.
@ -915,32 +950,32 @@ class KeyEventManager {
/// 4. Other native components (possibly non-Flutter).
///
/// 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
/// from being propagated to the next phase. This mechanism allows shortcuts
/// such as "Ctrl-C" to not generate a text "C" in the text field, or
/// shortcuts that are not handled by any components to trigger special alerts
/// (such as the "bonk" noise on macOS).
/// result is true, this phase _handles_ the event and prevents the event from
/// being propagated to the next phase. This mechanism allows shortcuts such
/// as "Ctrl-C" to not generate a text "C" in the text field, or shortcuts
/// that are not handled by any components to trigger special alerts (such as
/// the "bonk" noise on macOS).
///
/// In the second phase, known as "the key event system", the event is dispatched
/// to several destinations: [RawKeyboard]'s listeners,
/// [HardwareKeyboard]'s handlers, and [keyMessageHandler].
/// All destinations will always receive the event regardless of the handlers'
/// results. If any handler's result is true, then the overall result of the
/// second phase is true, and event propagation is stopped.
/// In the second phase, known as "the key event system", the event is
/// dispatched to several destinations: [RawKeyboard]'s listeners,
/// [HardwareKeyboard]'s handlers, and [keyMessageHandler]. All destinations
/// will always receive the event regardless of the handlers' results. If any
/// handler's result is true, then the overall result of the second phase is
/// true, and event propagation is stopped.
///
/// See also:
///
/// * [RawKeyboard.addListener], which adds a raw keyboard listener.
/// * [RawKeyboardListener], which is also implemented by adding a raw
/// keyboard listener.
/// * [HardwareKeyboard.addHandler], which adds a hardware keyboard handler.
/// * [RawKeyboard.addListener], which adds a raw keyboard listener.
/// * [RawKeyboardListener], which is also implemented by adding a raw
/// keyboard listener.
/// * [HardwareKeyboard.addHandler], which adds a hardware keyboard handler.
///
/// ## Advanced usages: Manual assignment or patching
///
/// If you are not using the focus system to manage focus, set this
/// attribute to a [KeyMessageHandler] that returns true if the propagation
/// on the platform should not be continued. If this field is null, key events
/// will be assumed to not have been handled by Flutter, a result of "false".
/// If you are not using the focus system to manage focus, set this attribute
/// to a [KeyMessageHandler] that returns true if the propagation on the
/// platform should not be continued. If this field is null, key events will
/// 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
/// 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
/// manager, to which callbacks can be added and removed.
///
/// You should not patch [keyMessageHandler] until the `FocusManager` has assigned
/// its callback. This is assured during any time within the widget lifecycle
/// (such as `initState`), or after calling `WidgetManager.instance`.
/// You should not patch [keyMessageHandler] until the `FocusManager` has
/// assigned its callback. This is assured during any time within the widget
/// lifecycle (such as `initState`), or after calling
/// `WidgetManager.instance`.
///
/// {@tool dartpad}
/// This example shows how to process key events that are not handled by any
/// focus handler (such as `Shortcuts`) by patching [keyMessageHandler].
/// This example shows how to process key events that are not
/// 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.
/// 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
/// out. Now try some text shortcuts, such as Ctrl+A. The KeyA press is
/// handled as a shortcut, and is not sent to the fallback handler and so is
/// not printed out.
/// handled by `Shortcuts` and will be sent to the fallback handler and
/// printed out. Now try some text shortcuts, such as Ctrl+A. The KeyA press
/// is handled as a shortcut, and is not sent to the fallback handler and so
/// is not printed out.
///
/// The key widget is `FallbackKeyEventRegistrar`, a necessity class to allow
/// reversible patching. `FallbackFocus` and `FallbackFocusNode` are also
@ -977,8 +1014,12 @@ class KeyEventManager {
///
/// See also:
///
/// * [HardwareKeyboard.addHandler], which accepts multiple global handlers
/// to process [KeyEvent]s
/// * [HardwareKeyboard.addHandler], which accepts multiple global handlers to
/// 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;
final HardwareKeyboard _hardwareKeyboard;
@ -1012,6 +1053,13 @@ class KeyEventManager {
/// Dispatch a key data to global and leaf listeners.
///
/// 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) {
_transitMode ??= KeyDataTransitMode.keyDataThenRawKeyData;
switch (_transitMode!) {
@ -1075,9 +1123,16 @@ class KeyEventManager {
/// Handles a raw key message.
///
/// This method is the handler to [SystemChannels.keyEvent], processing
/// the JSON form of the native key message and returns the responds for the
/// This method is the handler to [SystemChannels.keyEvent], processing the
/// JSON form of the native key message and returns the responds for the
/// 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 {
if (_transitMode == null) {
_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
/// 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:
///
/// * [RawKeyEventData.isModifierPressed], which accepts this enum as an
/// argument.
@Deprecated(
'No longer supported. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
enum KeyboardSide {
/// Matches if either the left, right or both versions of the key are pressed.
any,
@ -45,10 +53,18 @@ enum KeyboardSide {
/// 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:
///
/// * [RawKeyEventData.isModifierPressed], which accepts this enum as an
/// argument.
@Deprecated(
'No longer supported. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
enum ModifierKey {
/// The CTRL modifier key.
///
@ -106,6 +122,9 @@ enum ModifierKey {
/// 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
/// target platform's key event data structures.
///
@ -116,56 +135,112 @@ enum ModifierKey {
/// * [RawKeyDownEvent] and [RawKeyUpEvent], the classes that hold the
/// reference to [RawKeyEventData] subclasses.
/// * [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
abstract class RawKeyEventData with Diagnosticable {
/// Abstract const constructor. This constructor enables subclasses to provide
/// 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();
/// Returns true if the given [ModifierKey] was pressed at the time of this
/// 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
/// 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
/// 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 });
/// 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.
///
/// This method is deprecated and will be removed.
///
/// 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
/// [KeyboardSide.all] if pressed. If the given platform does not specify
/// the side, return [KeyboardSide.any].
@Deprecated(
'No longer available. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
KeyboardSide? getModifierSide(ModifierKey key);
/// 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.
///
/// This method is deprecated and will be removed. Use
/// [HardwareKeyboard.isControlPressed] instead.
///
/// 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);
/// 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.
///
/// This method is deprecated and will be removed. Use
/// [HardwareKeyboard.isShiftPressed] instead.
///
/// 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);
/// 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.
///
/// This method is deprecated and will be removed. Use
/// [HardwareKeyboard.isAltPressed] instead.
///
/// 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);
/// 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.
///
/// This method is deprecated and will be removed. Use
/// [HardwareKeyboard.isMetaPressed] instead.
///
/// 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);
/// 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.
///
/// 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 {
final Map<ModifierKey, KeyboardSide> result = <ModifierKey, KeyboardSide>{};
for (final ModifierKey key in ModifierKey.values) {
@ -254,6 +329,11 @@ abstract class RawKeyEventData with Diagnosticable {
/// 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
/// underlying platform's key events, which allows them to provide a high level
/// of fidelity but a low level of portability.
@ -265,20 +345,28 @@ abstract class RawKeyEventData with Diagnosticable {
///
/// See also:
///
/// * [LogicalKeyboardKey], an object that describes the logical meaning of a
/// key.
/// * [PhysicalKeyboardKey], an object that describes the physical location of
/// a key.
/// * [RawKeyDownEvent], a specialization for events representing the user
/// pressing a key.
/// * [RawKeyUpEvent], a specialization for events representing the user
/// releasing a key.
/// * [RawKeyboard], which uses this interface to expose key data.
/// * [RawKeyboardListener], a widget that listens for raw key events.
/// * [LogicalKeyboardKey], an object that describes the logical meaning of a
/// key.
/// * [PhysicalKeyboardKey], an object that describes the physical location of a
/// key.
/// * [RawKeyDownEvent], a specialization for events representing the user
/// pressing a key.
/// * [RawKeyUpEvent], a specialization for events representing the user
/// releasing a key.
/// * [RawKeyboard], which uses this interface to expose key data.
/// * [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
abstract class RawKeyEvent with Diagnosticable {
/// Abstract const constructor. This constructor enables subclasses to provide
/// 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({
required this.data,
this.character,
@ -290,6 +378,10 @@ abstract class RawKeyEvent with Diagnosticable {
///
/// [RawKeyEvent.repeat] will be derived from the current keyboard state,
/// 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) {
String? character;
RawKeyEventData dataFromWeb() {
@ -407,12 +499,26 @@ abstract class RawKeyEvent with Diagnosticable {
}
/// 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);
/// Returns true if a CTRL modifier key is pressed, regardless of which side
/// 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.
@Deprecated(
'Use HardwareKeyboard.instance.isControlPressed instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
bool get isControlPressed {
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
/// 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.
@Deprecated(
'Use HardwareKeyboard.instance.isShiftPressed instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
bool get isShiftPressed {
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
/// 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 same as [LogicalKeyboardKey.altRight] on some platforms (notably
/// Android). On platforms that can distinguish between `altRight` and
@ -435,6 +551,10 @@ abstract class RawKeyEvent with Diagnosticable {
/// tested for separately.
///
/// 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 {
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
/// 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.
@Deprecated(
'Use HardwareKeyboard.instance.isMetaPressed instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
bool get isMetaPressed {
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.
///
/// This class has been deprecated and will be removed. Use [KeyDownEvent]
/// instead.
///
/// 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 {
/// 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({
required super.data,
super.character,
@ -550,11 +688,22 @@ class RawKeyDownEvent extends RawKeyEvent {
/// The user has released a key on the keyboard.
///
/// This class has been deprecated and will be removed. Use [KeyUpEvent]
/// instead.
///
/// See also:
///
/// * [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 {
/// 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({
required super.data,
super.character,
@ -564,12 +713,22 @@ class RawKeyUpEvent extends RawKeyEvent {
/// 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.
///
/// 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
/// 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);
/// 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
/// underlying platform's key events, which makes them provide a high level of
/// fidelity but a low level of portability.
@ -583,34 +742,42 @@ typedef RawKeyEventHandler = bool Function(RawKeyEvent event);
///
/// ## Compared to [HardwareKeyboard]
///
/// [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:
///
/// 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.
/// * 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:
///
/// * [RawKeyDownEvent] and [RawKeyUpEvent], the classes used to describe
/// specific raw key events.
/// * [RawKeyboardListener], a widget that listens for raw key events.
/// * [SystemChannels.keyEvent], the low-level channel used for receiving
/// events from the system.
/// * [SystemChannels.keyEvent], the low-level channel used for receiving events
/// from the system.
/// * [HardwareKeyboard], the recommended replacement.
@Deprecated(
'Use HardwareKeyboard instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
class RawKeyboard {
@Deprecated(
'Use HardwareKeyboard instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
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._();
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 'keyboard_key.g.dart' show LogicalKeyboardKey, PhysicalKeyboardKey;
export 'raw_keyboard.dart' show KeyboardSide, ModifierKey;
// Android sets the 0x80000000 bit on a character to indicate that it is a
// combining character, so we use this mask to remove that bit to make it a
@ -19,14 +18,25 @@ const int _kCombiningCharacterMask = 0x7fffffff;
/// Platform-specific key event data for Android.
///
/// This class is deprecated and will be removed. Platform specific key event
/// data will no longer be available. See [KeyEvent] for what is available.
///
/// This object contains information about key events obtained from Android's
/// `KeyEvent` interface.
///
/// See also:
///
/// * [RawKeyboard], which uses this interface to expose key data.
/// * [RawKeyboard], which uses this interface to expose key data.
@Deprecated(
'Platform specific key event data is no longer available. See KeyEvent for what is available. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
class RawKeyEventDataAndroid extends RawKeyEventData {
/// Creates a key event data structure specific for Android.
@Deprecated(
'Platform specific key event data is no longer available. See KeyEvent for what is available. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
const RawKeyEventDataAndroid({
this.flags = 0,
this.codePoint = 0,

View File

@ -10,18 +10,28 @@ import 'raw_keyboard.dart';
export 'package:flutter/foundation.dart' show DiagnosticPropertiesBuilder;
export 'keyboard_key.g.dart' show LogicalKeyboardKey, PhysicalKeyboardKey;
export 'raw_keyboard.dart' show KeyboardSide, ModifierKey;
/// Platform-specific key event data for Fuchsia.
///
/// This class is deprecated and will be removed. Platform specific key event
/// data will no longer be available. See [KeyEvent] for what is available.
///
/// This object contains information about key events obtained from Fuchsia's
/// `KeyData` interface.
///
/// See also:
///
/// * [RawKeyboard], which uses this interface to expose key data.
/// * [RawKeyboard], which uses this interface to expose key data.
@Deprecated(
'Platform specific key event data is no longer available. See KeyEvent for what is available. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
class RawKeyEventDataFuchsia extends RawKeyEventData {
/// Creates a key event data structure specific for Fuchsia.
@Deprecated(
'Platform specific key event data is no longer available. See KeyEvent for what is available. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
const RawKeyEventDataFuchsia({
this.hidUsage = 0,
this.codePoint = 0,

View File

@ -10,18 +10,28 @@ import 'raw_keyboard.dart';
export 'package:flutter/foundation.dart' show DiagnosticPropertiesBuilder;
export 'keyboard_key.g.dart' show LogicalKeyboardKey, PhysicalKeyboardKey;
export 'raw_keyboard.dart' show KeyboardSide, ModifierKey;
/// Platform-specific key event data for iOS.
///
/// This class is deprecated and will be removed. Platform specific key event
/// data will no longer be available. See [KeyEvent] for what is available.
///
/// This object contains information about key events obtained from iOS'
/// `UIKey` interface.
///
/// See also:
///
/// * [RawKeyboard], which uses this interface to expose key data.
@Deprecated(
'Platform specific key event data is no longer available. See KeyEvent for what is available. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
class RawKeyEventDataIos extends RawKeyEventData {
/// Creates a key event data structure specific for iOS.
@Deprecated(
'Platform specific key event data is no longer available. See KeyEvent for what is available. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
const RawKeyEventDataIos({
this.characters = '',
this.charactersIgnoringModifiers = '',

View File

@ -10,18 +10,28 @@ import 'raw_keyboard.dart';
export 'package:flutter/foundation.dart' show DiagnosticPropertiesBuilder;
export 'keyboard_key.g.dart' show LogicalKeyboardKey, PhysicalKeyboardKey;
export 'raw_keyboard.dart' show KeyboardSide, ModifierKey;
/// Platform-specific key event data for Linux.
///
/// This class is deprecated and will be removed. Platform specific key event
/// data will no longer be available. See [KeyEvent] for what is available.
///
/// Different window toolkit implementations can map to different key codes. This class
/// will use the correct mapping depending on the [keyHelper] provided.
///
/// See also:
///
/// * [RawKeyboard], which uses this interface to expose key data.
@Deprecated(
'Platform specific key event data is no longer available. See KeyEvent for what is available. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
class RawKeyEventDataLinux extends RawKeyEventData {
/// Creates a key event data structure specific for Linux.
@Deprecated(
'Platform specific key event data is no longer available. See KeyEvent for what is available. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
const RawKeyEventDataLinux({
required this.keyHelper,
this.unicodeScalarValues = 0,
@ -170,8 +180,19 @@ class RawKeyEventDataLinux extends RawKeyEventData {
/// Given that there might be multiple window toolkit implementations (GLFW,
/// GTK, QT, etc), this creates a common interface for each of the
/// different toolkits.
///
/// This class is deprecated and will be removed. Platform specific key event
/// data will no longer be available. See [KeyEvent] for what is available.
@Deprecated(
'No longer supported. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
abstract class KeyHelper {
/// Create a KeyHelper implementation depending on the given toolkit.
@Deprecated(
'No longer supported. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
factory KeyHelper(String toolkit) {
if (toolkit == 'glfw') {
return GLFWKeyHelper();
@ -189,10 +210,18 @@ abstract class KeyHelper {
/// Returns a [KeyboardSide] enum value that describes which side or sides of
/// the given keyboard modifier key were pressed at the time of this event.
@Deprecated(
'No longer supported. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
KeyboardSide getModifierSide(ModifierKey key);
/// Returns true if the given [ModifierKey] was pressed at the time of this
/// event.
@Deprecated(
'No longer supported. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
bool isModifierPressed(ModifierKey key, int modifiers, {KeyboardSide side = KeyboardSide.any, required int keyCode, required bool isDown});
/// The numpad key from the specific key code mapping.
@ -206,6 +235,13 @@ abstract class KeyHelper {
}
/// Helper class that uses GLFW-specific key mappings.
///
/// This class is deprecated and will be removed. Platform specific key event
/// data will no longer be available. See [KeyEvent] for what is available.
@Deprecated(
'No longer supported. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
class GLFWKeyHelper implements KeyHelper {
/// This mask is used to check the [RawKeyEventDataLinux.modifiers] field to
/// test whether the CAPS LOCK modifier key is on.
@ -343,6 +379,13 @@ class GLFWKeyHelper implements KeyHelper {
}
/// Helper class that uses GTK-specific key mappings.
///
/// This class is deprecated and will be removed. Platform specific key event
/// data will no longer be available. See [KeyEvent] for what is available.
@Deprecated(
'No longer supported. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
class GtkKeyHelper implements KeyHelper {
/// This mask is used to check the [RawKeyEventDataLinux.modifiers] field to
/// test whether one of the SHIFT modifier keys is pressed.

View File

@ -10,7 +10,6 @@ import 'raw_keyboard.dart';
export 'package:flutter/foundation.dart' show DiagnosticPropertiesBuilder;
export 'keyboard_key.g.dart' show LogicalKeyboardKey, PhysicalKeyboardKey;
export 'raw_keyboard.dart' show KeyboardSide, ModifierKey;
/// Convert a UTF32 rune to its lower case.
int runeToLowerCase(int rune) {
@ -25,14 +24,25 @@ int runeToLowerCase(int rune) {
/// Platform-specific key event data for macOS.
///
/// This class is deprecated and will be removed. Platform specific key event
/// data will no longer be available. See [KeyEvent] for what is available.
///
/// This object contains information about key events obtained from macOS's
/// `NSEvent` interface.
///
/// See also:
///
/// * [RawKeyboard], which uses this interface to expose key data.
@Deprecated(
'Platform specific key event data is no longer available. See KeyEvent for what is available. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
class RawKeyEventDataMacOs extends RawKeyEventData {
/// Creates a key event data structure specific for macOS.
@Deprecated(
'Platform specific key event data is no longer available. See KeyEvent for what is available. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
const RawKeyEventDataMacOs({
this.characters = '',
this.charactersIgnoringModifiers = '',

View File

@ -10,7 +10,6 @@ import 'raw_keyboard.dart';
export 'package:flutter/foundation.dart' show DiagnosticPropertiesBuilder;
export 'keyboard_key.g.dart' show LogicalKeyboardKey, PhysicalKeyboardKey;
export 'raw_keyboard.dart' show KeyboardSide, ModifierKey;
String? _unicodeChar(String key) {
if (key.length == 1) {
@ -21,12 +20,23 @@ String? _unicodeChar(String key) {
/// Platform-specific key event data for Web.
///
/// This class is DEPRECATED. Platform specific key event data will no longer
/// available. See [KeyEvent] for what is available.
///
/// See also:
///
/// * [RawKeyboard], which uses this interface to expose key data.
@Deprecated(
'Platform specific key event data is no longer available. See KeyEvent for what is available. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
@immutable
class RawKeyEventDataWeb extends RawKeyEventData {
/// Creates a key event data structure specific for Web.
@Deprecated(
'Platform specific key event data is no longer available. See KeyEvent for what is available. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
const RawKeyEventDataWeb({
required this.code,
required this.key,

View File

@ -10,7 +10,6 @@ import 'raw_keyboard.dart';
export 'package:flutter/foundation.dart' show DiagnosticPropertiesBuilder;
export 'keyboard_key.g.dart' show LogicalKeyboardKey, PhysicalKeyboardKey;
export 'raw_keyboard.dart' show KeyboardSide, ModifierKey;
// Virtual key VK_PROCESSKEY in Win32 API.
//
@ -19,14 +18,25 @@ const int _vkProcessKey = 0xe5;
/// Platform-specific key event data for Windows.
///
/// This class is DEPRECATED. Platform specific key event data will no longer
/// available. See [KeyEvent] for what is available.
///
/// This object contains information about key events obtained from Windows's
/// win32 API.
///
/// See also:
///
/// * [RawKeyboard], which uses this interface to expose key data.
@Deprecated(
'Platform specific key event data is no longer available. See KeyEvent for what is available. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
class RawKeyEventDataWindows extends RawKeyEventData {
/// Creates a key event data structure specific for Windows.
@Deprecated(
'Platform specific key event data is no longer available. See KeyEvent for what is available. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
const RawKeyEventDataWindows({
this.keyCode = 0,
this.scanCode = 0,

View File

@ -103,10 +103,17 @@ KeyEventResult combineKeyEventResults(Iterable<KeyEventResult> results) {
/// Signature of a callback used by [Focus.onKey] and [FocusScope.onKey]
/// to receive key events.
///
/// This kind of callback is deprecated and will be removed at a future date.
/// Use [FocusOnKeyEventCallback] and associated APIs instead.
///
/// The [node] is the node that received the event.
///
/// Returns a [KeyEventResult] that describes how, and whether, the key event
/// was handled.
@Deprecated(
'Use FocusOnKeyEventCallback instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
typedef FocusOnKeyCallback = KeyEventResult Function(FocusNode node, RawKeyEvent event);
/// Signature of a callback used by [Focus.onKeyEvent] and [FocusScope.onKeyEvent]
@ -369,14 +376,13 @@ enum UnfocusDisposition {
/// {@template flutter.widgets.FocusNode.keyEvents}
/// ## Key Event Propagation
///
/// The [FocusManager] receives key events from [RawKeyboard] and
/// [HardwareKeyboard] and will pass them to the focused nodes. It starts with
/// the node with the primary focus, and will call the [onKey] or [onKeyEvent]
/// callback for that node. If the callback returns [KeyEventResult.ignored],
/// indicating that it did not handle the event, the [FocusManager] will move
/// to the parent of that node and call its [onKey] or [onKeyEvent]. If that
/// [onKey] or [onKeyEvent] returns [KeyEventResult.handled], then it will stop
/// propagating the event. If it reaches the root [FocusScopeNode],
/// The [FocusManager] receives key events from [HardwareKeyboard] and will pass
/// them to the focused nodes. It starts with the node with the primary focus,
/// and will call the [onKeyEvent] callback for that node. If the callback
/// returns [KeyEventResult.ignored], indicating that it did not handle the
/// event, the [FocusManager] will move to the parent of that node and call its
/// [onKeyEvent]. If that [onKeyEvent] returns [KeyEventResult.handled], then it
/// will stop propagating the event. If it reaches the root [FocusScopeNode],
/// [FocusManager.rootScope], the event is discarded.
/// {@endtemplate}
///
@ -429,11 +435,14 @@ class FocusNode with DiagnosticableTreeMixin, ChangeNotifier {
///
/// The [debugLabel] is ignored on release builds.
///
/// To receive key events that focuses on this node, pass a listener to `onKeyEvent`.
/// The `onKey` is a legacy API based on [RawKeyEvent] and will be deprecated
/// in the future.
/// To receive key events that focuses on this node, pass a listener to
/// `onKeyEvent`.
FocusNode({
String? debugLabel,
@Deprecated(
'Use onKeyEvent instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
this.onKey,
this.onKeyEvent,
bool skipTraversal = false,
@ -621,10 +630,17 @@ class FocusNode with DiagnosticableTreeMixin, ChangeNotifier {
/// Called if this focus node receives a key event while focused (i.e. when
/// [hasFocus] returns true).
///
/// This property is deprecated and will be removed at a future date. Use
/// [onKeyEvent] instead.
///
/// This is a legacy API based on [RawKeyEvent] and will be deprecated in the
/// future. Prefer [onKeyEvent] instead.
///
/// {@macro flutter.widgets.FocusNode.keyEvents}
@Deprecated(
'Use onKeyEvent instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
FocusOnKeyCallback? onKey;
/// Called if this focus node receives a key event while focused (i.e. when
@ -1035,13 +1051,16 @@ class FocusNode with DiagnosticableTreeMixin, ChangeNotifier {
/// node, and then [attach] called on the new node. This typically happens in
/// the [State.didUpdateWidget] method.
///
/// To receive key events that focuses on this node, pass a listener to `onKeyEvent`.
/// The `onKey` is a legacy API based on [RawKeyEvent] and will be deprecated
/// in the future.
/// To receive key events that focuses on this node, pass a listener to
/// `onKeyEvent`.
@mustCallSuper
FocusAttachment attach(
BuildContext? context, {
FocusOnKeyEventCallback? onKeyEvent,
@Deprecated(
'Use onKeyEvent instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
FocusOnKeyCallback? onKey,
}) {
_context = context;
@ -1241,6 +1260,10 @@ class FocusScopeNode extends FocusNode {
FocusScopeNode({
super.debugLabel,
super.onKeyEvent,
@Deprecated(
'Use onKeyEvent instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
super.onKey,
super.skipTraversal,
super.canRequestFocus,
@ -1432,8 +1455,8 @@ enum FocusHighlightStrategy {
/// The focus manager is responsible for tracking which [FocusNode] has the
/// primary input focus (the [primaryFocus]), holding the [FocusScopeNode] that
/// is the root of the focus tree (the [rootScope]), and what the current
/// [highlightMode] is. It also distributes key events from [KeyEventManager]
/// to the nodes in the focus tree.
/// [highlightMode] is. It also distributes [KeyEvent]s to the nodes in the
/// focus tree.
///
/// The singleton [FocusManager] instance is held by the [WidgetsBinding] as
/// [WidgetsBinding.focusManager], and can be conveniently accessed using the
@ -1490,10 +1513,10 @@ class FocusManager with DiagnosticableTreeMixin, ChangeNotifier {
/// Registers global input event handlers that are needed to manage focus.
///
/// This sets the [RawKeyboard.keyEventHandler] for the shared instance of
/// [RawKeyboard] and adds a route to the global entry in the gesture routing
/// table. As such, only one [FocusManager] instance should register its
/// global handlers.
/// This calls the [HardwareKeyboard.addHandler] on the shared instance of
/// [HardwareKeyboard] and adds a route to the global entry in the gesture
/// routing table. As such, only one [FocusManager] instance should register
/// its global handlers.
///
/// When this focus manager is no longer needed, calling [dispose] on it will
/// unregister these handlers.
@ -1856,6 +1879,9 @@ class _HighlightModeManager {
void registerGlobalHandlers() {
assert(ServicesBinding.instance.keyEventManager.keyMessageHandler == null);
// TODO(gspencergoog): Remove this when the RawKeyEvent system is
// deprecated, and replace it with registering a handler on the
// HardwareKeyboard.
ServicesBinding.instance.keyEventManager.keyMessageHandler = handleKeyMessage;
GestureBinding.instance.pointerRouter.addGlobalRoute(handlePointerEvent);
}
@ -1964,8 +1990,8 @@ class _HighlightModeManager {
}
// Walk the current focus from the leaf to the root, calling each node's
// onKey on the way up, and if one responds that they handled it or want to
// stop propagation, stop.
// onKeyEvent on the way up, and if one responds that they handled it or
// want to stop propagation, stop.
for (final FocusNode node in <FocusNode>[
FocusManager.instance.primaryFocus!,
...FocusManager.instance.primaryFocus!.ancestors,

View File

@ -119,6 +119,10 @@ class Focus extends StatefulWidget {
this.autofocus = false,
this.onFocusChange,
FocusOnKeyEventCallback? onKeyEvent,
@Deprecated(
'Use onKeyEvent instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
FocusOnKeyCallback? onKey,
bool? canRequestFocus,
bool? skipTraversal,
@ -228,8 +232,7 @@ class Focus extends StatefulWidget {
/// A handler for keys that are pressed when this object or one of its
/// children has focus.
///
/// This is a legacy API based on [RawKeyEvent] and will be deprecated in the
/// future. Prefer [onKeyEvent] instead.
/// This property is deprecated and will be removed. Use [onKeyEvent] instead.
///
/// Key events are first given to the [FocusNode] that has primary focus, and
/// if its [onKey] method return false, then they are given to each ancestor
@ -241,6 +244,10 @@ class Focus extends StatefulWidget {
/// keyboards in general. For text input, consider [TextField],
/// [EditableText], or [CupertinoTextField] instead, which do support these
/// things.
@Deprecated(
'Use onKeyEvent instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
FocusOnKeyCallback? get onKey => _onKey ?? focusNode?.onKey;
final FocusOnKeyCallback? _onKey;

View File

@ -21,16 +21,10 @@ export 'package:flutter/services.dart' show KeyEvent;
/// For text entry, consider using a [EditableText], which integrates with
/// on-screen keyboards and input method editors (IMEs).
///
/// The [KeyboardListener] is different from [RawKeyboardListener] in that
/// [KeyboardListener] uses the newer [HardwareKeyboard] API, which is
/// preferable.
///
/// See also:
///
/// * [EditableText], which should be used instead of this widget for text
/// entry.
/// * [RawKeyboardListener], a similar widget based on the old [RawKeyboard]
/// API.
class KeyboardListener extends StatelessWidget {
/// Creates a widget that receives keyboard events.
///

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
/// on a keyboard.
///
/// The [RawKeyboardListener] is deprecated and will be removed. Use
/// [KeyboardListener] instead.
///
/// A [RawKeyboardListener] is useful for listening to raw key events and
/// hardware buttons that are represented as keys. Typically used by games and
/// other apps that use keyboards for purposes other than text entry.
@ -21,21 +24,25 @@ export 'package:flutter/services.dart' show RawKeyEvent;
/// For text entry, consider using a [EditableText], which integrates with
/// on-screen keyboards and input method editors (IMEs).
///
/// The [RawKeyboardListener] is different from [KeyboardListener] in that
/// [RawKeyboardListener] uses the legacy [RawKeyboard] API. Use
/// [KeyboardListener] if possible.
///
/// See also:
///
/// * [EditableText], which should be used instead of this widget for text
/// entry.
/// * [KeyboardListener], a similar widget based on the newer
/// [HardwareKeyboard] API.
/// * [KeyboardListener], a similar widget based on the newer [HardwareKeyboard]
/// API.
@Deprecated(
'Use KeyboardListener instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
class RawKeyboardListener extends StatefulWidget {
/// Creates a widget that receives raw keyboard events.
///
/// For text entry, consider using a [EditableText], which integrates with
/// on-screen keyboards and input method editors (IMEs).
@Deprecated(
'Use KeyboardListener instead. '
'This feature was deprecated after v3.18.0-2.0.pre.',
)
const RawKeyboardListener({
super.key,
required this.focusNode,

View File

@ -508,9 +508,9 @@ class SingleActivator with Diagnosticable, MenuSerializableShortcut implements S
/// Whether this activator accepts repeat events of the [trigger] key.
///
/// If [includeRepeats] is true, the activator is checked on all
/// [RawKeyDownEvent] events for the [trigger] key. If [includeRepeats] is
/// false, only [trigger] key events which are not [KeyRepeatEvent]s will be
/// considered.
/// [KeyDownEvent] or [KeyRepeatEvent]s for the [trigger] key. If
/// [includeRepeats] is false, only [trigger] key events which are
/// [KeyDownEvent]s will be considered.
final bool includeRepeats;
@override
@ -601,10 +601,10 @@ class SingleActivator with Diagnosticable, MenuSerializableShortcut implements S
/// Shift keys are pressed or not, as long as the key event produces the
/// correct character.
///
/// By default, the activator is checked on all [RawKeyDownEvent] events for
/// the [character] in combination with the requested modifier keys. If
/// `includeRepeats` is false, only the [character] events with a false
/// [RawKeyDownEvent.repeat] attribute will be considered.
/// By default, the activator is checked on all [KeyDownEvent] or
/// [KeyRepeatEvent]s for the [character] in combination with the requested
/// modifier keys. If `includeRepeats` is false, only the [character] events
/// with that are [KeyDownEvent]s will be considered.
///
/// {@template flutter.widgets.shortcuts.CharacterActivator.alt}
/// On macOS and iOS, the [alt] flag indicates that the Option key () is
@ -679,9 +679,9 @@ class CharacterActivator with Diagnosticable, MenuSerializableShortcut implement
/// Whether this activator accepts repeat events of the [character].
///
/// If [includeRepeats] is true, the activator is checked on all
/// [RawKeyDownEvent] events for the [character]. If [includeRepeats] is
/// false, only the [character] events with a false [RawKeyDownEvent.repeat]
/// attribute will be considered.
/// [KeyDownEvent] and [KeyRepeatEvent]s for the [character]. If
/// [includeRepeats] is false, only the [character] events that are
/// [KeyDownEvent]s will be considered.
final bool includeRepeats;
/// The character which triggers the shortcut.
@ -694,7 +694,7 @@ class CharacterActivator with Diagnosticable, MenuSerializableShortcut implement
///
/// See also:
///
/// * [RawKeyEvent.character], the character of a key event.
/// * [KeyEvent.character], the character of a key event.
final String character;
@override

View File

@ -7788,6 +7788,9 @@ void main() {
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
await tester.pump();
expect(focusNode3.hasPrimaryFocus, isTrue);
// TODO(gspencergoog): Remove the variant when the deprecated
// KeySimulatorTransitModeVariant API is removed.
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Scrolling shortcuts are disabled in text fields', (WidgetTester tester) async {
@ -7822,6 +7825,9 @@ void main() {
await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
expect(scrollInvoked, isFalse);
// TODO(gspencergoog): Remove the variant when the deprecated
// KeySimulatorTransitModeVariant API is removed.
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Cupertino text field semantics', (WidgetTester tester) async {

View File

@ -7022,6 +7022,9 @@ void main() {
await tester.sendKeyEvent(LogicalKeyboardKey.arrowLeft);
await tester.sendKeyUpEvent(LogicalKeyboardKey.shift);
expect(controller.selection.extentOffset - controller.selection.baseOffset, -1);
// TODO(gspencergoog): Remove the variant when the deprecated
// KeySimulatorTransitModeVariant API is removed.
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Shift test 2', (WidgetTester tester) async {
@ -7040,6 +7043,9 @@ void main() {
await tester.sendKeyDownEvent(LogicalKeyboardKey.arrowRight);
await tester.pumpAndSettle();
expect(controller.selection.extentOffset - controller.selection.baseOffset, 1);
// TODO(gspencergoog): Remove the variant when the deprecated
// KeySimulatorTransitModeVariant API is removed.
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Control Shift test', (WidgetTester tester) async {
@ -7057,6 +7063,9 @@ void main() {
await tester.pumpAndSettle();
expect(controller.selection.extentOffset - controller.selection.baseOffset, 5);
// TODO(gspencergoog): Remove the variant when the deprecated
// KeySimulatorTransitModeVariant API is removed.
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Down and up test', (WidgetTester tester) async {
@ -7084,6 +7093,9 @@ void main() {
await tester.pumpAndSettle();
expect(controller.selection.extentOffset - controller.selection.baseOffset, 0);
// TODO(gspencergoog): Remove the variant when the deprecated
// KeySimulatorTransitModeVariant API is removed.
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Down and up test 2', (WidgetTester tester) async {
@ -7140,6 +7152,9 @@ void main() {
await tester.pumpAndSettle();
expect(controller.selection.extentOffset - controller.selection.baseOffset, -5);
// TODO(gspencergoog): Remove the variant when the deprecated
// KeySimulatorTransitModeVariant API is removed.
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Read only keyboard selection test', (WidgetTester tester) async {
@ -7160,6 +7175,9 @@ void main() {
await tester.sendKeyDownEvent(LogicalKeyboardKey.shift);
await tester.sendKeyDownEvent(LogicalKeyboardKey.arrowLeft);
expect(controller.selection.extentOffset - controller.selection.baseOffset, -1);
// TODO(gspencergoog): Remove the variant when the deprecated
// KeySimulatorTransitModeVariant API is removed.
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
}, skip: areKeyEventsHandledByPlatform); // [intended] only applies to platforms where we handle key events.
@ -7237,6 +7255,9 @@ void main() {
expect(find.text(expected), findsOneWidget, reason: 'Because text contains ${controller.text}');
},
skip: areKeyEventsHandledByPlatform, // [intended] only applies to platforms where we handle key events.
// TODO(gspencergoog): Remove the variant when the deprecated
// KeySimulatorTransitModeVariant API is removed.
// ignore: deprecated_member_use
variant: KeySimulatorTransitModeVariant.all()
);
@ -7290,6 +7311,9 @@ void main() {
expect(find.text(clipboardContent), findsOneWidget);
},
skip: areKeyEventsHandledByPlatform, // [intended] only applies to platforms where we handle key events.
// TODO(gspencergoog): Remove the variant when the deprecated
// KeySimulatorTransitModeVariant API is removed.
// ignore: deprecated_member_use
variant: KeySimulatorTransitModeVariant.all(),
);
@ -7369,6 +7393,9 @@ void main() {
expect(find.text(expected), findsOneWidget);
},
skip: areKeyEventsHandledByPlatform, // [intended] only applies to platforms where we handle key events.
// TODO(gspencergoog): Remove the variant when the deprecated
// KeySimulatorTransitModeVariant API is removed.
// ignore: deprecated_member_use
variant: KeySimulatorTransitModeVariant.all()
);
@ -7420,6 +7447,9 @@ void main() {
expect(find.text(expected), findsOneWidget);
},
skip: areKeyEventsHandledByPlatform, // [intended] only applies to platforms where we handle key events.
// TODO(gspencergoog): Remove the variant when the deprecated
// KeySimulatorTransitModeVariant API is removed.
// ignore: deprecated_member_use
variant: KeySimulatorTransitModeVariant.all()
);
@ -7474,6 +7504,9 @@ void main() {
expect(find.text(expected2), findsOneWidget);
},
skip: areKeyEventsHandledByPlatform, // [intended] only applies to platforms where we handle key events.
// TODO(gspencergoog): Remove the variant when the deprecated
// KeySimulatorTransitModeVariant API is removed.
// ignore: deprecated_member_use
variant: KeySimulatorTransitModeVariant.all(),
);
@ -7569,6 +7602,9 @@ void main() {
expect(c1.selection.extentOffset - c1.selection.baseOffset, -10);
},
skip: areKeyEventsHandledByPlatform, // [intended] only applies to platforms where we handle key events.
// TODO(gspencergoog): Remove the variant when the deprecated
// KeySimulatorTransitModeVariant API is removed.
// ignore: deprecated_member_use
variant: KeySimulatorTransitModeVariant.all()
);
@ -7646,6 +7682,9 @@ void main() {
expect(c2.selection.extentOffset - c2.selection.baseOffset, -5);
},
skip: areKeyEventsHandledByPlatform, // [intended] only applies to platforms where we handle key events.
// TODO(gspencergoog): Remove the variant when the deprecated
// KeySimulatorTransitModeVariant API is removed.
// ignore: deprecated_member_use
variant: KeySimulatorTransitModeVariant.all()
);

View File

@ -67,6 +67,7 @@ void main() {
equals(<LogicalKeyboardKey>{}));
expect(HardwareKeyboard.instance.lockModesEnabled,
equals(<KeyboardLockMode>{}));
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.keyDataThenRawKeyData());
testWidgetsWithLeakTracking('KeyEvent can tell which keys are pressed', (WidgetTester tester) async {
@ -101,6 +102,7 @@ void main() {
await simulateKeyUpEvent(LogicalKeyboardKey.numLock, platform: 'windows');
expect(HardwareKeyboard.instance.isPhysicalKeyPressed(PhysicalKeyboardKey.numLock), isFalse);
expect(HardwareKeyboard.instance.isLogicalKeyPressed(LogicalKeyboardKey.numLock), isFalse);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.keyDataThenRawKeyData());
testWidgetsWithLeakTracking('KeyboardManager synthesizes modifier keys in rawKeyData mode', (WidgetTester tester) async {
@ -228,6 +230,7 @@ void main() {
true);
expect(logs, <int>[3, 2, 1]);
logs.clear();
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
// Regression test for https://github.com/flutter/flutter/issues/99196 .
@ -277,6 +280,7 @@ void main() {
expect(ServicesBinding.instance.keyboard.physicalKeysPressed, equals(<PhysicalKeyboardKey>{
PhysicalKeyboardKey.keyA,
}));
// ignore: deprecated_member_use
}, variant: const KeySimulatorTransitModeVariant(<KeyDataTransitMode>{
KeyDataTransitMode.rawKeyData,
}));
@ -312,6 +316,7 @@ void main() {
)), false);
expect(logs, <int>[2, 1]);
logs.clear();
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.keyDataThenRawKeyData());
testWidgetsWithLeakTracking('Postpone synthesized key events when the queue is not empty', (WidgetTester tester) async {
@ -366,6 +371,7 @@ void main() {
expect(logs, <String>['RawKeyDownEvent', 'KeyDownEvent', 'KeyUpEvent']);
logs.clear();
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.keyDataThenRawKeyData());
// The first key data received from the engine might be an empty key data.
@ -505,6 +511,7 @@ void main() {
// If the previous state (key down) wasn't recorded, this key up event will
// trigger assertions.
expect(record, isNull);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('debugPrintKeyboardEvents causes logging of key events', (WidgetTester tester) async {

View File

@ -1014,6 +1014,7 @@ void main() {
false);
expect(logs, <int>[1, 3, 2]);
logs.clear();
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Exceptions from RawKeyboard listeners are caught and reported', (WidgetTester tester) async {
@ -2154,6 +2155,7 @@ void main() {
expect(events, isEmpty);
expect(lastHandled, true);
expect(RawKeyboard.instance.keysPressed, isEmpty);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.keyDataThenRawKeyData());
test('data.toString', () {

View File

@ -147,6 +147,7 @@ void main() {
await tester.sendKeyEvent(LogicalKeyboardKey.gameButtonA);
await tester.pumpAndSettle();
expect(checked, isTrue);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
group('error control test', () {

View File

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

View File

@ -12559,6 +12559,7 @@ void main() {
expect(controller.selection.isCollapsed, true);
expect(controller.selection.baseOffset, 0);
}
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('the toolbar is disposed when selection changes and there is no selectionControls', (WidgetTester tester) async {

View File

@ -352,6 +352,7 @@ void main() {
false);
expect(logs, <int>[20, 21, 10, 11]);
logs.clear();
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
});
@ -1269,6 +1270,7 @@ void main() {
// Since none of the focused nodes handle this event, nothing should
// receive it.
expect(receivedAnEvent, isEmpty);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Initial highlight mode guesses correctly.', (WidgetTester tester) async {
@ -1901,6 +1903,7 @@ void main() {
expect(await simulateKeyDownEvent(LogicalKeyboardKey.digit1), true);
expect(await simulateKeyUpEvent(LogicalKeyboardKey.digit1), false);
expect(logs, <int>[0, 1, 0, 1]);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('FocusManager.addLateKeyEventHandler works', (WidgetTester tester) async {
@ -1980,6 +1983,7 @@ void main() {
expect(await simulateKeyDownEvent(LogicalKeyboardKey.digit1), true);
expect(await simulateKeyUpEvent(LogicalKeyboardKey.digit1), false);
expect(logs, <int>[0, 1, 0, 1]);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('FocusManager notifies listeners when a widget loses focus because it was removed.', (WidgetTester tester) async {

View File

@ -2403,6 +2403,7 @@ void main() {
expect(Focus.of(lowerLeftKey.currentContext!).hasPrimaryFocus, isTrue);
await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp);
expect(Focus.of(upperLeftKey.currentContext!).hasPrimaryFocus, isTrue);
// ignore: deprecated_member_use
}, skip: isBrowser, variant: KeySimulatorTransitModeVariant.all()); // https://github.com/flutter/flutter/issues/35347
testWidgetsWithLeakTracking('Focus traversal actions works when current focus skip traversal', (WidgetTester tester) async {
@ -2458,6 +2459,7 @@ void main() {
expect(Focus.of(key2.currentContext!).hasPrimaryFocus, isTrue);
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
expect(Focus.of(key3.currentContext!).hasPrimaryFocus, isTrue);
// ignore: deprecated_member_use
}, skip: isBrowser, variant: KeySimulatorTransitModeVariant.all()); // https://github.com/flutter/flutter/issues/35347
testWidgetsWithLeakTracking('Focus traversal inside a vertical scrollable scrolls to stay visible.', (WidgetTester tester) async {
@ -2564,6 +2566,7 @@ void main() {
await tester.pump();
expect(topNode.hasPrimaryFocus, isTrue);
expect(controller.offset, equals(0.0));
// ignore: deprecated_member_use
}, skip: isBrowser, variant: KeySimulatorTransitModeVariant.all()); // https://github.com/flutter/flutter/issues/35347
testWidgetsWithLeakTracking('Focus traversal inside a horizontal scrollable scrolls to stay visible.', (WidgetTester tester) async {
@ -2671,6 +2674,7 @@ void main() {
await tester.pump();
expect(leftNode.hasPrimaryFocus, isTrue);
expect(controller.offset, equals(0.0));
// ignore: deprecated_member_use
}, skip: isBrowser, variant: KeySimulatorTransitModeVariant.all()); // https://github.com/flutter/flutter/issues/35347
testWidgetsWithLeakTracking('Arrow focus traversal actions can be re-enabled for text fields.', (WidgetTester tester) async {
@ -2802,6 +2806,7 @@ void main() {
expect(focusNodeUpperLeft.hasPrimaryFocus, isTrue);
await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp);
expect(focusNodeUpperLeft.hasPrimaryFocus, isTrue);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Focus traversal does not break when no focusable is available on a MaterialApp', (WidgetTester tester) async {
@ -2819,6 +2824,7 @@ void main() {
await tester.idle();
expect(events.length, 2);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Focus traversal does not throw when no focusable is available in a group', (WidgetTester tester) async {
@ -2854,6 +2860,7 @@ void main() {
await tester.idle();
expect(events.length, 2);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Custom requestFocusCallback gets called on focusInDirection up/down/left/right.', (WidgetTester tester) async {

View File

@ -155,6 +155,7 @@ void main() {
tester.getRect(find.byKey(const ValueKey<String>('Box 0'), skipOffstage: false)),
equals(const Rect.fromLTRB(0.0, 0.0, 800.0, 50.0)),
);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Vertical scrollables are scrolled when activated via keyboard.', (WidgetTester tester) async {
@ -227,6 +228,7 @@ void main() {
tester.getRect(find.byKey(const ValueKey<String>('Box 0'), skipOffstage: false)),
equals(const Rect.fromLTRB(0.0, 0.0, 800.0, 50.0)),
);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Horizontal scrollables are scrolled when activated via keyboard.', (WidgetTester tester) async {
@ -288,6 +290,7 @@ void main() {
tester.getRect(find.byKey(const ValueKey<String>('Box 0'), skipOffstage: false)),
equals(const Rect.fromLTRB(0.0, 0.0, 50.0, 600.0)),
);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Horizontal scrollables are scrolled the correct direction in RTL locales.', (WidgetTester tester) async {
@ -352,6 +355,7 @@ void main() {
tester.getRect(find.byKey(const ValueKey<String>('Box 0'), skipOffstage: false)),
equals(const Rect.fromLTRB(750.0, 0.0, 800.0, 600.0)),
);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Reversed vertical scrollables are scrolled when activated via keyboard.', (WidgetTester tester) async {
@ -428,6 +432,7 @@ void main() {
tester.getRect(find.byKey(const ValueKey<String>('Box 0'), skipOffstage: false)),
equals(const Rect.fromLTRB(0.0, 550.0, 800.0, 600.0)),
);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Reversed horizontal scrollables are scrolled when activated via keyboard.', (WidgetTester tester) async {
@ -489,6 +494,7 @@ void main() {
await tester.sendKeyUpEvent(modifierKey);
}
await tester.pumpAndSettle();
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Custom scrollables with a center sliver are scrolled when activated via keyboard.', (WidgetTester tester) async {
@ -561,6 +567,7 @@ void main() {
tester.getRect(find.byKey(const ValueKey<String>('Item 10'), skipOffstage: false)),
equals(const Rect.fromLTRB(0.0, 100.0, 800.0, 200.0)),
);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Can scroll using intents only', (WidgetTester tester) async {

View File

@ -1689,6 +1689,7 @@ void main() {
await tester.sendKeyDownEvent(LogicalKeyboardKey.shift);
await tester.sendKeyDownEvent(LogicalKeyboardKey.arrowLeft);
expect(controller.selection.extentOffset - controller.selection.baseOffset, -1);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Shift test 2', (WidgetTester tester) async {
@ -1701,6 +1702,7 @@ void main() {
await tester.sendKeyDownEvent(LogicalKeyboardKey.arrowRight);
await tester.pumpAndSettle();
expect(controller.selection.extentOffset - controller.selection.baseOffset, 1);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Control Shift test', (WidgetTester tester) async {
@ -1713,6 +1715,7 @@ void main() {
await tester.pumpAndSettle();
expect(controller.selection.extentOffset - controller.selection.baseOffset, -5);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Down and up test', (WidgetTester tester) async {
@ -1731,6 +1734,7 @@ void main() {
await tester.pumpAndSettle();
expect(controller.selection.extentOffset - controller.selection.baseOffset, 0);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Down and up test 2', (WidgetTester tester) async {
@ -1782,6 +1786,7 @@ void main() {
await tester.pumpAndSettle();
expect(controller.selection.extentOffset - controller.selection.baseOffset, -5);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
});
@ -1842,6 +1847,7 @@ void main() {
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
await tester.pumpAndSettle();
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Select all test', (WidgetTester tester) async {
@ -1877,6 +1883,7 @@ void main() {
expect(controller.selection.baseOffset, 0);
expect(controller.selection.extentOffset, 31);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('keyboard selection should call onSelectionChanged', (WidgetTester tester) async {
@ -1924,6 +1931,7 @@ void main() {
expect(newSelection!.extentOffset, i + 1);
newSelection = null;
}
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Changing positions of selectable text', (WidgetTester tester) async {
@ -2015,6 +2023,7 @@ void main() {
c1 = editableTextWidget.controller;
expect(c1.selection.extentOffset - c1.selection.baseOffset, -10);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Changing focus test', (WidgetTester tester) async {
@ -2085,6 +2094,7 @@ void main() {
expect(c1.selection.extentOffset - c1.selection.baseOffset, -5);
expect(c2.selection.extentOffset - c2.selection.baseOffset, -5);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('Caret works when maxLines is null', (WidgetTester tester) async {

View File

@ -353,6 +353,7 @@ void main() {
invoked = 0;
expect(HardwareKeyboard.instance.logicalKeysPressed, isEmpty);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('handles repeated events', (WidgetTester tester) async {
@ -379,6 +380,7 @@ void main() {
invoked = 0;
expect(HardwareKeyboard.instance.logicalKeysPressed, isEmpty);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('rejects repeated events if requested', (WidgetTester tester) async {
@ -406,6 +408,7 @@ void main() {
invoked = 0;
expect(HardwareKeyboard.instance.logicalKeysPressed, isEmpty);
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('handles Shift-Ctrl-C', (WidgetTester tester) async {
@ -1169,6 +1172,7 @@ void main() {
await tester.sendKeyUpEvent(LogicalKeyboardKey.shiftLeft);
expect(invoked, 1);
invoked = 0;
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('handles repeated events', (WidgetTester tester) async {
@ -1189,6 +1193,7 @@ void main() {
await tester.sendKeyUpEvent(LogicalKeyboardKey.shiftLeft);
expect(invoked, 2);
invoked = 0;
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('rejects repeated events if requested', (WidgetTester tester) async {
@ -1209,6 +1214,7 @@ void main() {
await tester.sendKeyUpEvent(LogicalKeyboardKey.shiftLeft);
expect(invoked, 1);
invoked = 0;
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('handles Alt, Ctrl and Meta', (WidgetTester tester) async {
@ -1255,6 +1261,7 @@ void main() {
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlRight);
expect(invoked, 1);
invoked = 0;
// ignore: deprecated_member_use
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('isActivatedBy works as expected', (WidgetTester tester) async {

View File

@ -1159,17 +1159,18 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
}
_announcements = <CapturedAccessibilityAnnouncement>[];
// ignore: deprecated_member_use
ServicesBinding.instance.keyEventManager.keyMessageHandler = null;
buildOwner!.focusManager = FocusManager()..registerGlobalHandlers();
// Disabling the warning because @visibleForTesting doesn't take the testing
// framework itself into account, but we don't want it visible outside of
// tests.
// ignore: invalid_use_of_visible_for_testing_member
// ignore: invalid_use_of_visible_for_testing_member, deprecated_member_use
RawKeyboard.instance.clearKeysPressed();
// ignore: invalid_use_of_visible_for_testing_member
HardwareKeyboard.instance.clearState();
// ignore: invalid_use_of_visible_for_testing_member
// ignore: invalid_use_of_visible_for_testing_member, deprecated_member_use
keyEventManager.clearState();
// ignore: invalid_use_of_visible_for_testing_member
RendererBinding.instance.initMouseTracker();

View File

@ -1858,9 +1858,6 @@ abstract class WidgetController {
/// simulated event. If not specified, it uses a default derived from the
/// logical `key`.
///
/// Whether the event is sent through [RawKeyEvent] or [KeyEvent] is
/// controlled by [debugKeyEventSimulatorTransitModeOverride].
///
/// Keys that are down when the test completes are cleared after each test.
///
/// This method sends both the key down and the key up events, to simulate a
@ -1903,9 +1900,6 @@ abstract class WidgetController {
/// simulated event. If not specified, it uses a default derived from the
/// logical `key`.
///
/// Whether the event is sent through [RawKeyEvent] or [KeyEvent] is
/// controlled by [debugKeyEventSimulatorTransitModeOverride].
///
/// Keys that are down when the test completes are cleared after each test.
///
/// Returns true if the key event was handled by the framework.
@ -1939,9 +1933,6 @@ abstract class WidgetController {
/// the simulated event. If not specified, it uses a default from the US
/// keyboard layout for the corresponding logical `key`.
///
/// Whether the event is sent through [RawKeyEvent] or [KeyEvent] is
/// controlled by [debugKeyEventSimulatorTransitModeOverride].
///
/// Returns true if the key event was handled by the framework.
///
/// See also:
@ -1976,10 +1967,6 @@ abstract class WidgetController {
/// simulated event. If not specified, it uses a default derived from the
/// logical `key`.
///
/// Whether the event is sent through [RawKeyEvent] or [KeyEvent] is
/// controlled by [debugKeyEventSimulatorTransitModeOverride]. If through [RawKeyEvent],
/// this method is equivalent to [sendKeyDownEvent].
///
/// Keys that are down when the test completes are cleared after each test.
///
/// Returns true if the key event was handled by the framework.

View File

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

View File

@ -17,6 +17,7 @@ void _verifyKeyEvent<T extends KeyEvent>(KeyEvent event, PhysicalKeyboardKey phy
expect(event.synthesized, false);
}
// ignore: deprecated_member_use
void _verifyRawKeyEvent<T extends RawKeyEvent>(RawKeyEvent event, PhysicalKeyboardKey physical, LogicalKeyboardKey logical, String? character) {
expect(event, isA<T>());
expect(event.physicalKey, physical);
@ -38,13 +39,16 @@ Future<void> _shouldThrow<T extends Error>(AsyncValueGetter<void> func) async {
void main() {
testWidgets('simulates keyboard events (RawEvent)', (WidgetTester tester) async {
// ignore: deprecated_member_use
debugKeyEventSimulatorTransitModeOverride = KeyDataTransitMode.rawKeyData;
// ignore: deprecated_member_use
final List<RawKeyEvent> events = <RawKeyEvent>[];
final FocusNode focusNode = FocusNode();
await tester.pumpWidget(
// ignore: deprecated_member_use
RawKeyboardListener(
focusNode: focusNode,
onKey: events.add,
@ -68,11 +72,14 @@ void main() {
for (int i = 0; i < events.length; ++i) {
final bool isEven = i.isEven;
if (isEven) {
// ignore: deprecated_member_use
expect(events[i].runtimeType, equals(RawKeyDownEvent));
} else {
// ignore: deprecated_member_use
expect(events[i].runtimeType, equals(RawKeyUpEvent));
}
if (i < 4) {
// ignore: deprecated_member_use
expect(events[i].data.isModifierPressed(ModifierKey.shiftModifier, side: KeyboardSide.left), equals(isEven));
}
}
@ -82,10 +89,12 @@ void main() {
await tester.pumpWidget(Container());
focusNode.dispose();
// ignore: deprecated_member_use
debugKeyEventSimulatorTransitModeOverride = null;
});
testWidgets('simulates keyboard events (KeyData then RawKeyEvent)', (WidgetTester tester) async {
// ignore: deprecated_member_use
debugKeyEventSimulatorTransitModeOverride = KeyDataTransitMode.keyDataThenRawKeyData;
final List<KeyEvent> events = <KeyEvent>[];
@ -245,10 +254,12 @@ void main() {
await tester.pumpWidget(Container());
focusNode.dispose();
// ignore: deprecated_member_use
debugKeyEventSimulatorTransitModeOverride = null;
});
testWidgets('simulates using the correct transit mode: rawKeyData', (WidgetTester tester) async {
// ignore: deprecated_member_use
debugKeyEventSimulatorTransitModeOverride = KeyDataTransitMode.rawKeyData;
final List<Object> events = <Object>[];
@ -257,6 +268,7 @@ void main() {
await tester.pumpWidget(
Focus(
focusNode: focusNode,
// ignore: deprecated_member_use
onKey: (FocusNode node, RawKeyEvent event) {
events.add(event);
return KeyEventResult.ignored;
@ -277,7 +289,9 @@ void main() {
expect(events.length, 2);
expect(events[0], isA<KeyEvent>());
_verifyKeyEvent<KeyDownEvent>(events[0] as KeyEvent, PhysicalKeyboardKey.keyA, LogicalKeyboardKey.keyA, 'a');
// ignore: deprecated_member_use
expect(events[1], isA<RawKeyEvent>());
// ignore: deprecated_member_use
_verifyRawKeyEvent<RawKeyDownEvent>(events[1] as RawKeyEvent, PhysicalKeyboardKey.keyA, LogicalKeyboardKey.keyA, 'a');
events.clear();
@ -289,22 +303,27 @@ void main() {
expect(events.length, 2);
expect(events[0], isA<KeyEvent>());
_verifyKeyEvent<KeyUpEvent>(events[0] as KeyEvent, PhysicalKeyboardKey.keyA, LogicalKeyboardKey.keyA, null);
// ignore: deprecated_member_use
expect(events[1], isA<RawKeyEvent>());
// ignore: deprecated_member_use
_verifyRawKeyEvent<RawKeyUpEvent>(events[1] as RawKeyEvent, PhysicalKeyboardKey.keyA, LogicalKeyboardKey.keyB, null);
events.clear();
// Manually switch the transit mode to `keyDataThenRawKeyData`. This will
// never happen in real applications so the assertion error can verify that
// the transit mode is correctly applied.
// ignore: deprecated_member_use
debugKeyEventSimulatorTransitModeOverride = KeyDataTransitMode.keyDataThenRawKeyData;
await _shouldThrow<AssertionError>(() =>
simulateKeyUpEvent(LogicalKeyboardKey.keyB, physicalKey: PhysicalKeyboardKey.keyA));
// ignore: deprecated_member_use
debugKeyEventSimulatorTransitModeOverride = null;
});
testWidgets('simulates using the correct transit mode: keyDataThenRawKeyData', (WidgetTester tester) async {
// ignore: deprecated_member_use
debugKeyEventSimulatorTransitModeOverride = KeyDataTransitMode.keyDataThenRawKeyData;
final List<Object> events = <Object>[];
@ -313,6 +332,7 @@ void main() {
await tester.pumpWidget(
Focus(
focusNode: focusNode,
// ignore: deprecated_member_use
onKey: (FocusNode node, RawKeyEvent event) {
events.add(event);
return KeyEventResult.ignored;
@ -333,7 +353,9 @@ void main() {
expect(events.length, 2);
expect(events[0], isA<KeyEvent>());
_verifyKeyEvent<KeyDownEvent>(events[0] as KeyEvent, PhysicalKeyboardKey.keyA, LogicalKeyboardKey.keyA, 'a');
// ignore: deprecated_member_use
expect(events[1], isA<RawKeyEvent>());
// ignore: deprecated_member_use
_verifyRawKeyEvent<RawKeyDownEvent>(events[1] as RawKeyEvent, PhysicalKeyboardKey.keyA, LogicalKeyboardKey.keyA, 'a');
events.clear();
@ -345,6 +367,7 @@ void main() {
await _shouldThrow<AssertionError>(() =>
simulateKeyUpEvent(LogicalKeyboardKey.keyB, physicalKey: PhysicalKeyboardKey.keyA));
// ignore: deprecated_member_use
debugKeyEventSimulatorTransitModeOverride = null;
});
}