Change some usage of RawKeyEvent to KeyEvent in preparation for deprecation (#136420)

## Description

This converts some usages of `RawKeyEvent` to `KeyEvent` to prepare the repo for deprecation of `RawKeyEvent`, and swaps out the `raw_keyboard.dart` manual test for `hardware_keyboard.dart`.

## Related Issues
 - https://github.com/flutter/flutter/issues/136419

## Tests
 - Just refactoring code, no semantic changes.
This commit is contained in:
Greg Spencer
2023-10-13 17:25:18 -07:00
committed by GitHub
parent 33db5d7a87
commit 3ef32f0407
7 changed files with 110 additions and 167 deletions

View File

@@ -46,7 +46,7 @@ class _MyKeyExampleState extends State<MyKeyExample> {
// Handles the key events from the Focus widget and updates the
// _message.
KeyEventResult _handleKeyEvent(FocusNode node, RawKeyEvent event) {
KeyEventResult _handleKeyEvent(FocusNode node, KeyEvent event) {
setState(() {
if (event.logicalKey == LogicalKeyboardKey.keyQ) {
_message = 'Pressed the "Q" key!';
@@ -73,7 +73,7 @@ class _MyKeyExampleState extends State<MyKeyExample> {
style: textTheme.headlineMedium!,
child: Focus(
focusNode: _focusNode,
onKey: _handleKeyEvent,
onKeyEvent: _handleKeyEvent,
child: ListenableBuilder(
listenable: _focusNode,
builder: (BuildContext context, Widget? child) {

View File

@@ -46,7 +46,7 @@ class _MyPhysicalKeyExampleState extends State<MyPhysicalKeyExample> {
// Handles the key events from the RawKeyboardListener and update the
// _message.
KeyEventResult _handleKeyEvent(FocusNode node, RawKeyEvent event) {
KeyEventResult _handleKeyEvent(FocusNode node, KeyEvent event) {
setState(() {
if (event.physicalKey == PhysicalKeyboardKey.keyA) {
_message = 'Pressed the key next to CAPS LOCK!';
@@ -73,7 +73,7 @@ class _MyPhysicalKeyExampleState extends State<MyPhysicalKeyExample> {
style: textTheme.headlineMedium!,
child: Focus(
focusNode: _focusNode,
onKey: _handleKeyEvent,
onKeyEvent: _handleKeyEvent,
child: ListenableBuilder(
listenable: _focusNode,
builder: (BuildContext context, Widget? child) {