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> {
Widget result = _buildWidgetApp(context);
result = Focus(
canRequestFocus: false,
onKey: (FocusNode node, RawKeyEvent event) {
if (event is! RawKeyDownEvent || event.logicalKey != LogicalKeyboardKey.escape) {
onKeyEvent: (FocusNode node, KeyEvent event) {
if ((event is! KeyDownEvent && event is! KeyRepeatEvent) ||
event.logicalKey != LogicalKeyboardKey.escape) {
return KeyEventResult.ignored;
}
return Tooltip.dismissAllToolTips() ? KeyEventResult.handled : KeyEventResult.ignored;
......
......@@ -2809,8 +2809,9 @@ void main() {
await tester.pumpWidget(MaterialApp(home: Container()));
RawKeyboard.instance.addListener((RawKeyEvent event) {
HardwareKeyboard.instance.addHandler((KeyEvent event) {
events.add(event);
return true;
});
await tester.idle();
......@@ -2829,7 +2830,7 @@ void main() {
});
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(
WidgetsApp(
......@@ -2843,8 +2844,9 @@ void main() {
),
);
RawKeyboard.instance.addListener((RawKeyEvent event) {
HardwareKeyboard.instance.addHandler((KeyEvent event) {
events.add(event);
return true;
});
await tester.idle();
......
......@@ -1895,7 +1895,7 @@ void main() {
testWidgetsWithLeakTracking('Changing positions of selectable text', (WidgetTester tester) async {
final FocusNode focusNode = FocusNode();
addTearDown(focusNode.dispose);
final List<RawKeyEvent> events = <RawKeyEvent>[];
final List<KeyEvent> events = <KeyEvent>[];
final Key key1 = UniqueKey();
final Key key2 = UniqueKey();
......@@ -1904,9 +1904,9 @@ void main() {
MaterialApp(
home:
Material(
child: RawKeyboardListener(
child: KeyboardListener(
focusNode: focusNode,
onKey: events.add,
onKeyEvent: events.add,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
......@@ -1947,9 +1947,9 @@ void main() {
MaterialApp(
home:
Material(
child: RawKeyboardListener(
child: KeyboardListener(
focusNode: focusNode,
onKey: events.add,
onKeyEvent: events.add,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
......@@ -1986,7 +1986,7 @@ void main() {
testWidgetsWithLeakTracking('Changing focus test', (WidgetTester tester) async {
final FocusNode focusNode = FocusNode();
addTearDown(focusNode.dispose);
final List<RawKeyEvent> events = <RawKeyEvent>[];
final List<KeyEvent> events = <KeyEvent>[];
final Key key1 = UniqueKey();
final Key key2 = UniqueKey();
......@@ -1995,9 +1995,9 @@ void main() {
MaterialApp(
home:
Material(
child: RawKeyboardListener(
child: KeyboardListener(
focusNode: focusNode,
onKey: events.add,
onKeyEvent: events.add,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
......
......@@ -175,7 +175,7 @@ void main() {
expect(invoked, 0);
invoked = 0;
expect(RawKeyboard.instance.keysPressed, isEmpty);
expect(HardwareKeyboard.instance.logicalKeysPressed, isEmpty);
});
test('LogicalKeySet.hashCode is stable', () {
......@@ -352,7 +352,7 @@ void main() {
expect(invoked, 1);
invoked = 0;
expect(RawKeyboard.instance.keysPressed, isEmpty);
expect(HardwareKeyboard.instance.logicalKeysPressed, isEmpty);
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('handles repeated events', (WidgetTester tester) async {
......@@ -378,7 +378,7 @@ void main() {
expect(invoked, 2);
invoked = 0;
expect(RawKeyboard.instance.keysPressed, isEmpty);
expect(HardwareKeyboard.instance.logicalKeysPressed, isEmpty);
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('rejects repeated events if requested', (WidgetTester tester) async {
......@@ -405,7 +405,7 @@ void main() {
expect(invoked, 1);
invoked = 0;
expect(RawKeyboard.instance.keysPressed, isEmpty);
expect(HardwareKeyboard.instance.logicalKeysPressed, isEmpty);
}, variant: KeySimulatorTransitModeVariant.all());
testWidgetsWithLeakTracking('handles Shift-Ctrl-C', (WidgetTester tester) async {
......@@ -455,7 +455,7 @@ void main() {
expect(invoked, 0);
invoked = 0;
expect(RawKeyboard.instance.keysPressed, isEmpty);
expect(HardwareKeyboard.instance.logicalKeysPressed, isEmpty);
});
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