Unverified Commit 909e529e authored by Greg Spencer's avatar Greg Spencer Committed by GitHub

Convert some usage of `RawKeyEvent`, et al to `KeyEvent` (#139329)

## Description

This converts some uses of `RawKeyEvent` to `KeyEvent` in preparation for deprecating `RawKeyEvent`.

## Related Issues
 - https://github.com/flutter/flutter/issues/136419
parent 2d60241d
...@@ -1079,8 +1079,9 @@ class _MaterialAppState extends State<MaterialApp> { ...@@ -1079,8 +1079,9 @@ class _MaterialAppState extends State<MaterialApp> {
Widget result = _buildWidgetApp(context); Widget result = _buildWidgetApp(context);
result = Focus( result = Focus(
canRequestFocus: false, canRequestFocus: false,
onKey: (FocusNode node, RawKeyEvent event) { onKeyEvent: (FocusNode node, KeyEvent event) {
if (event is! RawKeyDownEvent || event.logicalKey != LogicalKeyboardKey.escape) { if ((event is! KeyDownEvent && event is! KeyRepeatEvent) ||
event.logicalKey != LogicalKeyboardKey.escape) {
return KeyEventResult.ignored; return KeyEventResult.ignored;
} }
return Tooltip.dismissAllToolTips() ? KeyEventResult.handled : KeyEventResult.ignored; return Tooltip.dismissAllToolTips() ? KeyEventResult.handled : KeyEventResult.ignored;
......
...@@ -2809,8 +2809,9 @@ void main() { ...@@ -2809,8 +2809,9 @@ void main() {
await tester.pumpWidget(MaterialApp(home: Container())); await tester.pumpWidget(MaterialApp(home: Container()));
RawKeyboard.instance.addListener((RawKeyEvent event) { HardwareKeyboard.instance.addHandler((KeyEvent event) {
events.add(event); events.add(event);
return true;
}); });
await tester.idle(); await tester.idle();
...@@ -2829,7 +2830,7 @@ void main() { ...@@ -2829,7 +2830,7 @@ void main() {
}); });
testWidgetsWithLeakTracking('Focus traversal does not break when no focusable is available on a WidgetsApp', (WidgetTester tester) async { testWidgetsWithLeakTracking('Focus traversal does not break when no focusable is available on a WidgetsApp', (WidgetTester tester) async {
final List<RawKeyEvent> events = <RawKeyEvent>[]; final List<KeyEvent> events = <KeyEvent>[];
await tester.pumpWidget( await tester.pumpWidget(
WidgetsApp( WidgetsApp(
...@@ -2843,8 +2844,9 @@ void main() { ...@@ -2843,8 +2844,9 @@ void main() {
), ),
); );
RawKeyboard.instance.addListener((RawKeyEvent event) { HardwareKeyboard.instance.addHandler((KeyEvent event) {
events.add(event); events.add(event);
return true;
}); });
await tester.idle(); await tester.idle();
......
...@@ -1895,7 +1895,7 @@ void main() { ...@@ -1895,7 +1895,7 @@ void main() {
testWidgetsWithLeakTracking('Changing positions of selectable text', (WidgetTester tester) async { testWidgetsWithLeakTracking('Changing positions of selectable text', (WidgetTester tester) async {
final FocusNode focusNode = FocusNode(); final FocusNode focusNode = FocusNode();
addTearDown(focusNode.dispose); addTearDown(focusNode.dispose);
final List<RawKeyEvent> events = <RawKeyEvent>[]; final List<KeyEvent> events = <KeyEvent>[];
final Key key1 = UniqueKey(); final Key key1 = UniqueKey();
final Key key2 = UniqueKey(); final Key key2 = UniqueKey();
...@@ -1904,9 +1904,9 @@ void main() { ...@@ -1904,9 +1904,9 @@ void main() {
MaterialApp( MaterialApp(
home: home:
Material( Material(
child: RawKeyboardListener( child: KeyboardListener(
focusNode: focusNode, focusNode: focusNode,
onKey: events.add, onKeyEvent: events.add,
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[ children: <Widget>[
...@@ -1947,9 +1947,9 @@ void main() { ...@@ -1947,9 +1947,9 @@ void main() {
MaterialApp( MaterialApp(
home: home:
Material( Material(
child: RawKeyboardListener( child: KeyboardListener(
focusNode: focusNode, focusNode: focusNode,
onKey: events.add, onKeyEvent: events.add,
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[ children: <Widget>[
...@@ -1986,7 +1986,7 @@ void main() { ...@@ -1986,7 +1986,7 @@ void main() {
testWidgetsWithLeakTracking('Changing focus test', (WidgetTester tester) async { testWidgetsWithLeakTracking('Changing focus test', (WidgetTester tester) async {
final FocusNode focusNode = FocusNode(); final FocusNode focusNode = FocusNode();
addTearDown(focusNode.dispose); addTearDown(focusNode.dispose);
final List<RawKeyEvent> events = <RawKeyEvent>[]; final List<KeyEvent> events = <KeyEvent>[];
final Key key1 = UniqueKey(); final Key key1 = UniqueKey();
final Key key2 = UniqueKey(); final Key key2 = UniqueKey();
...@@ -1995,9 +1995,9 @@ void main() { ...@@ -1995,9 +1995,9 @@ void main() {
MaterialApp( MaterialApp(
home: home:
Material( Material(
child: RawKeyboardListener( child: KeyboardListener(
focusNode: focusNode, focusNode: focusNode,
onKey: events.add, onKeyEvent: events.add,
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[ children: <Widget>[
......
...@@ -175,7 +175,7 @@ void main() { ...@@ -175,7 +175,7 @@ void main() {
expect(invoked, 0); expect(invoked, 0);
invoked = 0; invoked = 0;
expect(RawKeyboard.instance.keysPressed, isEmpty); expect(HardwareKeyboard.instance.logicalKeysPressed, isEmpty);
}); });
test('LogicalKeySet.hashCode is stable', () { test('LogicalKeySet.hashCode is stable', () {
...@@ -352,7 +352,7 @@ void main() { ...@@ -352,7 +352,7 @@ void main() {
expect(invoked, 1); expect(invoked, 1);
invoked = 0; invoked = 0;
expect(RawKeyboard.instance.keysPressed, isEmpty); expect(HardwareKeyboard.instance.logicalKeysPressed, isEmpty);
}, variant: KeySimulatorTransitModeVariant.all()); }, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('handles repeated events', (WidgetTester tester) async { testWidgetsWithLeakTracking('handles repeated events', (WidgetTester tester) async {
...@@ -378,7 +378,7 @@ void main() { ...@@ -378,7 +378,7 @@ void main() {
expect(invoked, 2); expect(invoked, 2);
invoked = 0; invoked = 0;
expect(RawKeyboard.instance.keysPressed, isEmpty); expect(HardwareKeyboard.instance.logicalKeysPressed, isEmpty);
}, variant: KeySimulatorTransitModeVariant.all()); }, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('rejects repeated events if requested', (WidgetTester tester) async { testWidgetsWithLeakTracking('rejects repeated events if requested', (WidgetTester tester) async {
...@@ -405,7 +405,7 @@ void main() { ...@@ -405,7 +405,7 @@ void main() {
expect(invoked, 1); expect(invoked, 1);
invoked = 0; invoked = 0;
expect(RawKeyboard.instance.keysPressed, isEmpty); expect(HardwareKeyboard.instance.logicalKeysPressed, isEmpty);
}, variant: KeySimulatorTransitModeVariant.all()); }, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('handles Shift-Ctrl-C', (WidgetTester tester) async { testWidgetsWithLeakTracking('handles Shift-Ctrl-C', (WidgetTester tester) async {
...@@ -455,7 +455,7 @@ void main() { ...@@ -455,7 +455,7 @@ void main() {
expect(invoked, 0); expect(invoked, 0);
invoked = 0; invoked = 0;
expect(RawKeyboard.instance.keysPressed, isEmpty); expect(HardwareKeyboard.instance.logicalKeysPressed, isEmpty);
}); });
testWidgetsWithLeakTracking('isActivatedBy works as expected', (WidgetTester tester) async { testWidgetsWithLeakTracking('isActivatedBy works as expected', (WidgetTester tester) async {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment