Skip to content

Commit

Permalink
Fix links and header case in key-event-migration guide (#9922)
Browse files Browse the repository at this point in the history
  • Loading branch information
parlough authored Dec 14, 2023
1 parent d93a46c commit bcf233f
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/release/breaking-changes/key-event-migration.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Migrate RawKeyEvent/RawKeyboard system to KeyEvent/HardwareKeyboard system
description: >
description: >-
The raw key event subsystem has been superseded by the key event subsystem,
and APIs that use RawKeyEvent and RawKeyboard are converted to KeyEvent and
HardwareKeyboard.
Expand All @@ -18,12 +18,16 @@ In the original key event subsystem, handling each platform's quirks in the
framework and in client apps caused overly complex code, and the old system
didn't properly represent the true state of key events on the system.

[RawKeyboard] is the legacy API, and has been deprecated and will be removed in
the future. The replacements are [HardwareKeyboard] and [KeyEvent] APIs (such as
[FocusNode.onKeyEvent]).
The legacy API [`RawKeyboard`][] has been deprecated
and will be removed in the future.
The [`HardwareKeyboard`][] and [`KeyEvent`][] APIs replace this legacy API.
An example of this change is [`FocusNode.onKeyEvent`][]
replacing `FocusNode.onKey`.

Behavior-wise, [RawKeyboard] provided a less unified, less regular event model
than [HardwareKeyboard] does. For example:
The behavior of [`RawKeyboard`][] provided a
less unified and less regular event model
than [`HardwareKeyboard`][] does.
Consider the following examples:

* Down events were not always matched with an up event, and vice versa (the set
of pressed keys was silently updated).
Expand All @@ -44,7 +48,7 @@ that will occur when the deprecated APIs are removed.

Below are the APIs that have been deprecated.

### Deprecated APIs That Have an Equivalent
### Deprecated APIs that have an equivalent

* [`Focus.onKey`][] => [`Focus.onKeyEvent`][]
* [`FocusNode.attach`][]'s `onKey` argument => `onKeyEvent` argument
Expand All @@ -58,7 +62,7 @@ Below are the APIs that have been deprecated.
* [`RawKeyEvent`][] => [`KeyEvent`][]
* [`RawKeyUpEvent`][] => [`KeyUpEvent`][]

### APIs That Have Been Discontinued
### APIs that have been discontinued

These APIs are no longer needed once there is only one key event system, or
their functionality is no longer offered.
Expand Down Expand Up @@ -87,8 +91,9 @@ their functionality is no longer offered.

## Migration guide

APIs provided by the Flutter framework are already migrated. Migration is needed
only if any of the classes or methods listed in the previous section are used.
The Flutter framework libraries have already been migrated.
If your code uses any of the classes or methods listed in
the previous section, migrate to these new APIs.

### Migrating your code that uses `RawKeyEvent`

Expand Down Expand Up @@ -208,10 +213,10 @@ KeyEventResult _handleKeyEvent(KeyEvent _) {
}
```

Be careful to check conditionals: a [`KeyRepeatEvent`][] is also a key down event,
but it is a different type (it is not a subclass of [`KeyDownEvent`][]), so
don't assume that `keyEvent is! KeyDownEvent` only allows key up events, because
both `KeyDownEvent` and `KeyRepeatEvent` need to be checked.
Though it is not a subclass of [`KeyDownEvent`][],
a [`KeyRepeatEvent`][] is also a key down event.
Don't assume that `keyEvent is! KeyDownEvent` only allows key up events.
Check both `KeyDownEvent` and `KeyRepeatEvent`.

## Timeline

Expand Down

0 comments on commit bcf233f

Please sign in to comment.