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
59400bfc
Unverified
Commit
59400bfc
authored
Nov 23, 2021
by
Taha Tesser
Committed by
GitHub
Nov 23, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Request focus in `onTap` callback from `DropdownButton` (#93716)
parent
03861e57
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
0 deletions
+49
-0
dropdown.dart
packages/flutter/lib/src/material/dropdown.dart
+1
-0
dropdown_test.dart
packages/flutter/test/material/dropdown_test.dart
+48
-0
No files found.
packages/flutter/lib/src/material/dropdown.dart
View file @
59400bfc
...
@@ -1276,6 +1276,7 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi
...
@@ -1276,6 +1276,7 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi
borderRadius:
widget
.
borderRadius
,
borderRadius:
widget
.
borderRadius
,
);
);
focusNode
?.
requestFocus
();
navigator
.
push
(
_dropdownRoute
!).
then
<
void
>((
_DropdownRouteResult
<
T
>?
newValue
)
{
navigator
.
push
(
_dropdownRoute
!).
then
<
void
>((
_DropdownRouteResult
<
T
>?
newValue
)
{
_removeDropdownRoute
();
_removeDropdownRoute
();
if
(!
mounted
||
newValue
==
null
)
if
(!
mounted
||
newValue
==
null
)
...
...
packages/flutter/test/material/dropdown_test.dart
View file @
59400bfc
...
@@ -2775,6 +2775,54 @@ void main() {
...
@@ -2775,6 +2775,54 @@ void main() {
expect
(
Focus
.
of
(
tester
.
element
(
find
.
byKey
(
const
ValueKey
<
int
>(
91
)).
last
)).
hasPrimaryFocus
,
isFalse
);
expect
(
Focus
.
of
(
tester
.
element
(
find
.
byKey
(
const
ValueKey
<
int
>(
91
)).
last
)).
hasPrimaryFocus
,
isFalse
);
});
});
testWidgets
(
'DropdownButton onTap callback can request focus'
,
(
WidgetTester
tester
)
async
{
final
FocusNode
focusNode
=
FocusNode
(
debugLabel:
'DropdownButton'
)..
addListener
(()
{
});
int
?
value
=
1
;
final
List
<
int
>
hugeMenuItems
=
List
<
int
>.
generate
(
100
,
(
int
index
)
=>
index
);
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
body:
Center
(
child:
StatefulBuilder
(
builder:
(
BuildContext
context
,
StateSetter
setState
)
{
return
DropdownButton
<
int
>(
focusNode:
focusNode
,
onChanged:
(
int
?
newValue
)
{
setState
(()
{
value
=
newValue
;
});
},
value:
value
,
itemHeight:
null
,
items:
hugeMenuItems
.
map
<
DropdownMenuItem
<
int
>>((
int
item
)
{
return
DropdownMenuItem
<
int
>(
key:
ValueKey
<
int
>(
item
),
value:
item
,
child:
Text
(
item
.
toString
()),
);
}).
toList
(),
);
},
),
),
),
),
);
await
tester
.
pump
();
// Pump a frame for autofocus to take effect.
expect
(
focusNode
.
hasPrimaryFocus
,
isFalse
);
await
tester
.
tap
(
find
.
text
(
'1'
));
await
tester
.
pumpAndSettle
();
// Close the dropdown menu.
await
tester
.
tapAt
(
const
Offset
(
1.0
,
1.0
));
await
tester
.
pumpAndSettle
();
expect
(
focusNode
.
hasPrimaryFocus
,
isTrue
);
});
testWidgets
(
'DropdownButton changes selected item with arrow keys'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'DropdownButton changes selected item with arrow keys'
,
(
WidgetTester
tester
)
async
{
final
FocusNode
focusNode
=
FocusNode
(
debugLabel:
'DropdownButton'
);
final
FocusNode
focusNode
=
FocusNode
(
debugLabel:
'DropdownButton'
);
String
?
value
=
'one'
;
String
?
value
=
'one'
;
...
...
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