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
8d87e66f
Commit
8d87e66f
authored
Nov 28, 2016
by
Adam Barth
Committed by
GitHub
Nov 28, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Defunct RawKeyboardListeners shouldn't receive events (#7058)
parent
fcf41fc7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
0 deletions
+42
-0
raw_keyboard_listener.dart
packages/flutter/lib/src/widgets/raw_keyboard_listener.dart
+2
-0
raw_keyboard_listener_test.dart
...ages/flutter/test/widgets/raw_keyboard_listener_test.dart
+40
-0
No files found.
packages/flutter/lib/src/widgets/raw_keyboard_listener.dart
View file @
8d87e66f
...
...
@@ -82,12 +82,14 @@ class _RawKeyboardListenerState extends State<RawKeyboardListener> {
if
(
_listening
)
return
;
RawKeyboard
.
instance
.
addListener
(
_handleRawKeyEvent
);
_listening
=
true
;
}
void
_detachKeyboardIfAttached
()
{
if
(!
_listening
)
return
;
RawKeyboard
.
instance
.
removeListener
(
_handleRawKeyEvent
);
_listening
=
false
;
}
void
_handleRawKeyEvent
(
RawKeyEvent
event
)
{
...
...
packages/flutter/test/widgets/raw_keyboard_listener_test.dart
View file @
8d87e66f
...
...
@@ -51,4 +51,44 @@ void main() {
expect
(
typedData
.
codePoint
,
0x64
);
expect
(
typedData
.
modifiers
,
0x08
);
});
testWidgets
(
'Defunct listeners do not receive events'
,
(
WidgetTester
tester
)
async
{
List
<
RawKeyEvent
>
events
=
<
RawKeyEvent
>[];
await
tester
.
pumpWidget
(
new
RawKeyboardListener
(
focused:
true
,
onKey:
(
RawKeyEvent
event
)
{
events
.
add
(
event
);
},
child:
new
Container
(),
));
sendFakeKeyEvent
(<
String
,
dynamic
>{
'type'
:
'keydown'
,
'keymap'
:
'fuchsia'
,
'hidUsage'
:
0x04
,
'codePoint'
:
0x64
,
'modifiers'
:
0x08
,
});
await
tester
.
idle
();
expect
(
events
.
length
,
1
);
events
.
clear
();
await
tester
.
pumpWidget
(
new
Container
());
sendFakeKeyEvent
(<
String
,
dynamic
>{
'type'
:
'keydown'
,
'keymap'
:
'fuchsia'
,
'hidUsage'
:
0x04
,
'codePoint'
:
0x64
,
'modifiers'
:
0x08
,
});
await
tester
.
idle
();
expect
(
events
.
length
,
0
);
});
}
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