Skip to content

Commit 4b3cf9b

Browse files
authored
Add reference to HardwareKeyboard in RawKeyboard documentation (#118607)
1 parent 6fafbc3 commit 4b3cf9b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

packages/flutter/lib/src/services/raw_keyboard.dart

+19
Original file line numberDiff line numberDiff line change
@@ -585,13 +585,32 @@ typedef RawKeyEventHandler = bool Function(RawKeyEvent event);
585585
/// These key events are typically only key events generated by a hardware
586586
/// keyboard, and not those from software keyboards or input method editors.
587587
///
588+
/// ## Compared to [HardwareKeyboard]
589+
///
590+
/// [RawKeyboard] is the legacy API, and will be deprecated and removed in the
591+
/// future. It is recommended to always use [HardwareKeyboard] and [KeyEvent]
592+
/// APIs (such as [FocusNode.onKeyEvent]) to handle key events.
593+
///
594+
/// Behavior-wise, [RawKeyboard] provides a less unified, less regular
595+
/// event model than [HardwareKeyboard]. For example:
596+
///
597+
/// * Down events might not be matched with an up event, and vice versa (the
598+
/// set of pressed keys is silently updated).
599+
/// * The logical key of the down event might not be the same as that of the up
600+
/// event.
601+
/// * Down events and repeat events are not easily distinguishable (must be
602+
/// tracked manually).
603+
/// * Lock modes (such as CapsLock) only have their "enabled" state recorded.
604+
/// There's no way to acquire their pressing state.
605+
///
588606
/// See also:
589607
///
590608
/// * [RawKeyDownEvent] and [RawKeyUpEvent], the classes used to describe
591609
/// specific raw key events.
592610
/// * [RawKeyboardListener], a widget that listens for raw key events.
593611
/// * [SystemChannels.keyEvent], the low-level channel used for receiving
594612
/// events from the system.
613+
/// * [HardwareKeyboard], the recommended replacement.
595614
class RawKeyboard {
596615
RawKeyboard._();
597616

0 commit comments

Comments
 (0)