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:
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user