Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
c5573ea3
Unverified
Commit
c5573ea3
authored
Jul 30, 2021
by
Tong Mu
Committed by
GitHub
Jul 30, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Keyboard] Accept empty events (#87152)
parent
33fd4f15
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
1 deletion
+66
-1
hardware_keyboard.dart
packages/flutter/lib/src/services/hardware_keyboard.dart
+8
-1
hardware_keyboard_test.dart
packages/flutter/test/services/hardware_keyboard_test.dart
+58
-0
No files found.
packages/flutter/lib/src/services/hardware_keyboard.dart
View file @
c5573ea3
...
...
@@ -787,8 +787,15 @@ class KeyEventManager {
assert
(
false
,
'Should never encounter KeyData when transitMode is rawKeyData.'
);
return
false
;
case
KeyDataTransitMode
.
keyDataThenRawKeyData
:
assert
((
data
.
physical
==
0
&&
data
.
logical
==
0
)
||
(
data
.
physical
!=
0
&&
data
.
logical
!=
0
));
// Postpone key event dispatching until the handleRawKeyMessage.
_keyEventsSinceLastMessage
.
add
(
_eventFromData
(
data
));
//
// Having 0 as the physical or logical ID indicates an empty key data,
// transmitted to ensure that the transit mode is correctly inferred.
if
(
data
.
physical
!=
0
&&
data
.
logical
!=
0
)
{
_keyEventsSinceLastMessage
.
add
(
_eventFromData
(
data
));
}
return
false
;
}
}
...
...
packages/flutter/test/services/hardware_keyboard_test.dart
View file @
c5573ea3
...
...
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:ui'
as
ui
;
import
'package:flutter/services.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
...
...
@@ -162,4 +164,60 @@ void main() {
expect
(
logs
,
<
int
>[
3
,
2
,
1
]);
logs
.
clear
();
},
variant:
KeySimulatorTransitModeVariant
.
all
());
// The first key data received from the engine might be an empty key data.
// In that case, the key data should not be converted to any [KeyEvent]s,
// but is only used so that *a* key data comes before the raw key message
// and makes [KeyEventManager] infer [KeyDataTransitMode.keyDataThenRawKeyData].
testWidgets
(
'Empty keyData yields no event but triggers inferrence'
,
(
WidgetTester
tester
)
async
{
final
List
<
KeyEvent
>
events
=
<
KeyEvent
>[];
final
List
<
RawKeyEvent
>
rawEvents
=
<
RawKeyEvent
>[];
tester
.
binding
.
keyboard
.
addHandler
((
KeyEvent
event
)
{
events
.
add
(
event
);
return
true
;
});
RawKeyboard
.
instance
.
addListener
((
RawKeyEvent
event
)
{
rawEvents
.
add
(
event
);
});
tester
.
binding
.
keyEventManager
.
handleKeyData
(
const
ui
.
KeyData
(
type:
ui
.
KeyEventType
.
down
,
timeStamp:
Duration
.
zero
,
logical:
0
,
physical:
0
,
character:
'a'
,
synthesized:
false
,
));
tester
.
binding
.
keyEventManager
.
handleRawKeyMessage
(<
String
,
dynamic
>{
'type'
:
'keydown'
,
'keymap'
:
'windows'
,
'keyCode'
:
0x04
,
'scanCode'
:
0x04
,
'characterCodePoint'
:
0
,
'modifiers'
:
0
,
});
expect
(
events
.
length
,
0
);
expect
(
rawEvents
.
length
,
1
);
// Dispatch another key data to ensure it's in
// [KeyDataTransitMode.keyDataThenRawKeyData] mode (otherwise assertion
// will be thrown upon a KeyData).
tester
.
binding
.
keyEventManager
.
handleKeyData
(
const
ui
.
KeyData
(
type:
ui
.
KeyEventType
.
down
,
timeStamp:
Duration
.
zero
,
logical:
0x22
,
physical:
0x70034
,
character:
'"'
,
synthesized:
false
,
));
tester
.
binding
.
keyEventManager
.
handleRawKeyMessage
(<
String
,
dynamic
>{
'type'
:
'keydown'
,
'keymap'
:
'windows'
,
'keyCode'
:
0x04
,
'scanCode'
:
0x04
,
'characterCodePoint'
:
0
,
'modifiers'
:
0
,
});
expect
(
events
.
length
,
1
);
expect
(
rawEvents
.
length
,
2
);
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment