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
c8d876c5
Unverified
Commit
c8d876c5
authored
Nov 17, 2021
by
Greg Spencer
Committed by
GitHub
Nov 17, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix CallbackShortcuts to only call shortcuts when triggered (#93693)
parent
819823e7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
7 deletions
+24
-7
shortcuts.dart
packages/flutter/lib/src/widgets/shortcuts.dart
+5
-3
shortcuts_test.dart
packages/flutter/test/widgets/shortcuts_test.dart
+19
-4
No files found.
packages/flutter/lib/src/widgets/shortcuts.dart
View file @
c8d876c5
...
...
@@ -1005,9 +1005,11 @@ class CallbackShortcuts extends StatelessWidget {
// throws, by providing the activator and event as arguments that will appear
// in the stack trace.
bool
_applyKeyBinding
(
ShortcutActivator
activator
,
RawKeyEvent
event
)
{
if
(
activator
.
accepts
(
event
,
RawKeyboard
.
instance
))
{
bindings
[
activator
]!.
call
();
return
true
;
if
(
activator
.
triggers
?.
contains
(
event
.
logicalKey
)
??
true
)
{
if
(
activator
.
accepts
(
event
,
RawKeyboard
.
instance
))
{
bindings
[
activator
]!.
call
();
return
true
;
}
}
return
false
;
}
...
...
packages/flutter/test/widgets/shortcuts_test.dart
View file @
c8d876c5
...
...
@@ -1126,12 +1126,16 @@ void main() {
group
(
'CallbackShortcuts'
,
()
{
testWidgets
(
'trigger on key events'
,
(
WidgetTester
tester
)
async
{
int
invoked
=
0
;
int
invokedA
=
0
;
int
invokedB
=
0
;
await
tester
.
pumpWidget
(
CallbackShortcuts
(
bindings:
<
ShortcutActivator
,
VoidCallback
>{
const
SingleActivator
(
LogicalKeyboardKey
.
keyA
):
()
{
invoked
+=
1
;
invokedA
+=
1
;
},
const
SingleActivator
(
LogicalKeyboardKey
.
keyB
):
()
{
invokedB
+=
1
;
},
},
child:
const
Focus
(
...
...
@@ -1143,9 +1147,20 @@ void main() {
await
tester
.
pump
();
await
tester
.
sendKeyDownEvent
(
LogicalKeyboardKey
.
keyA
);
expect
(
invoked
,
equals
(
1
));
await
tester
.
pump
();
expect
(
invokedA
,
equals
(
1
));
expect
(
invokedB
,
equals
(
0
));
await
tester
.
sendKeyUpEvent
(
LogicalKeyboardKey
.
keyA
);
expect
(
invoked
,
equals
(
1
));
expect
(
invokedA
,
equals
(
1
));
expect
(
invokedB
,
equals
(
0
));
invokedA
=
0
;
invokedB
=
0
;
await
tester
.
sendKeyDownEvent
(
LogicalKeyboardKey
.
keyB
);
expect
(
invokedA
,
equals
(
0
));
expect
(
invokedB
,
equals
(
1
));
await
tester
.
sendKeyUpEvent
(
LogicalKeyboardKey
.
keyB
);
expect
(
invokedA
,
equals
(
0
));
expect
(
invokedB
,
equals
(
1
));
});
testWidgets
(
'nested CallbackShortcuts stop propagation'
,
(
WidgetTester
tester
)
async
{
...
...
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