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
bbec650b
Unverified
Commit
bbec650b
authored
Jul 15, 2022
by
Taha Tesser
Committed by
GitHub
Jul 15, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
`DropdownButton`: Fix hint alignment when `selectedItemBuilder` is non-null. (#106731)
parent
cf342254
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
190 additions
and
96 deletions
+190
-96
dropdown.dart
packages/flutter/lib/src/material/dropdown.dart
+5
-5
dropdown_test.dart
packages/flutter/test/material/dropdown_test.dart
+185
-91
No files found.
packages/flutter/lib/src/material/dropdown.dart
View file @
bbec650b
...
...
@@ -1397,17 +1397,17 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi
int
?
hintIndex
;
if
(
widget
.
hint
!=
null
||
(!
_enabled
&&
widget
.
disabledHint
!=
null
))
{
Widget
displayedHint
=
_enabled
?
widget
.
hint
!
:
widget
.
disabledHint
??
widget
.
hint
!;
if
(
widget
.
selectedItemBuilder
==
null
)
{
displayedHint
=
_DropdownMenuItemContainer
(
alignment:
widget
.
alignment
,
child:
displayedHint
);
}
final
Widget
displayedHint
=
_enabled
?
widget
.
hint
!
:
widget
.
disabledHint
??
widget
.
hint
!;
hintIndex
=
items
.
length
;
items
.
add
(
DefaultTextStyle
(
style:
_textStyle
!.
copyWith
(
color:
Theme
.
of
(
context
).
hintColor
),
child:
IgnorePointer
(
ignoringSemantics:
false
,
child:
displayedHint
,
child:
_DropdownMenuItemContainer
(
alignment:
widget
.
alignment
,
child:
displayedHint
,
),
),
));
}
...
...
packages/flutter/test/material/dropdown_test.dart
View file @
bbec650b
...
...
@@ -195,6 +195,30 @@ Widget buildFrame({
);
}
Widget
buildDropdownWithHint
(
{
required
AlignmentDirectional
alignment
,
required
bool
isExpanded
,
bool
enableSelectedItemBuilder
=
false
,
}){
return
buildFrame
(
mediaSize:
const
Size
(
800
,
600
),
itemHeight:
100.0
,
alignment:
alignment
,
isExpanded:
isExpanded
,
selectedItemBuilder:
enableSelectedItemBuilder
?
(
BuildContext
context
)
{
return
menuItems
.
map
<
Widget
>((
String
item
)
{
return
Container
(
color:
const
Color
(
0xff00ff00
),
child:
Text
(
item
),
);
}).
toList
();
}
:
null
,
hint:
const
Text
(
'hint'
),
);
}
class
TestApp
extends
StatefulWidget
{
const
TestApp
({
super
.
key
,
...
...
@@ -3657,155 +3681,225 @@ void main() {
});
testWidgets
(
'DropdownButton hint alignment'
,
(
WidgetTester
tester
)
async
{
final
Key
buttonKey
=
UniqueKey
();
const
String
hintText
=
'hint'
;
// DropdownButton with `isExpanded: false` (default)
// AlignmentDirectional.centerStart (default)
await
tester
.
pumpWidget
(
buildFrame
(
buttonKey:
buttonKey
,
mediaSize:
const
Size
(
800
,
600
),
itemHeight:
100.0
,
hint:
const
Text
(
hintText
)),
);
await
tester
.
pumpWidget
(
buildDropdownWithHint
(
alignment:
AlignmentDirectional
.
centerStart
,
isExpanded:
false
,
));
expect
(
tester
.
getTopLeft
(
find
.
text
(
hintText
)).
dx
,
348.0
);
expect
(
tester
.
getTopLeft
(
find
.
text
(
hintText
)).
dy
,
292.0
);
// AlignmentDirectional.topStart
await
tester
.
pumpWidget
(
buildFrame
(
buttonKey:
buttonKey
,
mediaSize:
const
Size
(
800
,
600
),
await
tester
.
pumpWidget
(
buildDropdownWithHint
(
alignment:
AlignmentDirectional
.
topStart
,
itemHeight:
100.0
,
hint:
const
Text
(
hintText
)),
);
isExpanded:
false
,
));
expect
(
tester
.
getTopLeft
(
find
.
text
(
hintText
)).
dx
,
348.0
);
expect
(
tester
.
getTopLeft
(
find
.
text
(
hintText
)).
dy
,
250.0
);
// AlignmentDirectional.bottomStart
await
tester
.
pumpWidget
(
buildFrame
(
buttonKey:
buttonKey
,
mediaSize:
const
Size
(
800
,
600
),
await
tester
.
pumpWidget
(
buildDropdownWithHint
(
alignment:
AlignmentDirectional
.
bottomStart
,
itemHeight:
100.0
,
hint:
const
Text
(
hintText
)),
);
isExpanded:
false
,
));
expect
(
tester
.
getBottomLeft
(
find
.
text
(
hintText
)).
dx
,
348.0
);
expect
(
tester
.
getBottomLeft
(
find
.
text
(
hintText
)).
dy
,
350.0
);
// AlignmentDirectional.center
await
tester
.
pumpWidget
(
buildFrame
(
buttonKey:
buttonKey
,
mediaSize:
const
Size
(
800
,
600
),
await
tester
.
pumpWidget
(
buildDropdownWithHint
(
alignment:
AlignmentDirectional
.
center
,
itemHeight:
100.0
,
hint:
const
Text
(
hintText
)),
);
isExpanded:
false
,
));
expect
(
tester
.
getCenter
(
find
.
text
(
hintText
)).
dx
,
388.0
);
expect
(
tester
.
getCenter
(
find
.
text
(
hintText
)).
dy
,
300.0
);
// AlignmentDirectional.topEnd
await
tester
.
pumpWidget
(
buildFrame
(
buttonKey:
buttonKey
,
mediaSize:
const
Size
(
800
,
600
),
await
tester
.
pumpWidget
(
buildDropdownWithHint
(
alignment:
AlignmentDirectional
.
topEnd
,
itemHeight:
100.0
,
hint:
const
Text
(
hintText
)),
);
isExpanded:
false
,
));
expect
(
tester
.
getTopRight
(
find
.
text
(
hintText
)).
dx
,
428.0
);
expect
(
tester
.
getTopRight
(
find
.
text
(
hintText
)).
dy
,
250.0
);
// AlignmentDirectional.centerEnd
await
tester
.
pumpWidget
(
buildFrame
(
buttonKey:
buttonKey
,
mediaSize:
const
Size
(
800
,
600
),
await
tester
.
pumpWidget
(
buildDropdownWithHint
(
alignment:
AlignmentDirectional
.
centerEnd
,
itemHeight:
100.0
,
hint:
const
Text
(
hintText
)),
);
isExpanded:
false
,
));
expect
(
tester
.
getTopRight
(
find
.
text
(
hintText
)).
dx
,
428.0
);
expect
(
tester
.
getTopRight
(
find
.
text
(
hintText
)).
dy
,
292.0
);
// AlignmentDirectional.topEnd
await
tester
.
pumpWidget
(
buildFrame
(
buttonKey:
buttonKey
,
mediaSize:
const
Size
(
800
,
600
),
// AlignmentDirectional.bottomEnd
await
tester
.
pumpWidget
(
buildDropdownWithHint
(
alignment:
AlignmentDirectional
.
bottomEnd
,
itemHeight:
100.0
,
hint:
const
Text
(
hintText
)),
);
isExpanded:
false
,
));
expect
(
tester
.
getTopRight
(
find
.
text
(
hintText
)).
dx
,
428.0
);
expect
(
tester
.
getTopRight
(
find
.
text
(
hintText
)).
dy
,
334.0
);
// DropdownButton with `isExpanded: true`
// AlignmentDirectional.centerStart (default)
await
tester
.
pumpWidget
(
buildFrame
(
buttonKey:
buttonKey
,
mediaSize:
const
Size
(
800
,
600
),
itemHeight:
100.0
,
await
tester
.
pumpWidget
(
buildDropdownWithHint
(
alignment:
AlignmentDirectional
.
centerStart
,
isExpanded:
true
,
hint:
const
Text
(
hintText
)),
);
));
expect
(
tester
.
getTopLeft
(
find
.
text
(
hintText
)).
dx
,
0.0
);
expect
(
tester
.
getTopLeft
(
find
.
text
(
hintText
)).
dy
,
292.0
);
// AlignmentDirectional.topStart
await
tester
.
pumpWidget
(
buildFrame
(
buttonKey:
buttonKey
,
mediaSize:
const
Size
(
800
,
600
),
itemHeight:
100.0
,
isExpanded:
true
,
await
tester
.
pumpWidget
(
buildDropdownWithHint
(
alignment:
AlignmentDirectional
.
topStart
,
hint:
const
Text
(
hintText
))
,
);
isExpanded:
true
,
)
)
;
expect
(
tester
.
getTopLeft
(
find
.
text
(
hintText
)).
dx
,
0.0
);
expect
(
tester
.
getTopLeft
(
find
.
text
(
hintText
)).
dy
,
250.0
);
// AlignmentDirectional.bottomStart
await
tester
.
pumpWidget
(
buildFrame
(
buttonKey:
buttonKey
,
mediaSize:
const
Size
(
800
,
600
),
itemHeight:
100.0
,
isExpanded:
true
,
await
tester
.
pumpWidget
(
buildDropdownWithHint
(
alignment:
AlignmentDirectional
.
bottomStart
,
hint:
const
Text
(
hintText
))
,
);
isExpanded:
true
,
)
)
;
expect
(
tester
.
getBottomLeft
(
find
.
text
(
hintText
)).
dx
,
0.0
);
expect
(
tester
.
getBottomLeft
(
find
.
text
(
hintText
)).
dy
,
350.0
);
// AlignmentDirectional.center
await
tester
.
pumpWidget
(
buildFrame
(
buttonKey:
buttonKey
,
mediaSize:
const
Size
(
800
,
600
),
itemHeight:
100.0
,
await
tester
.
pumpWidget
(
buildDropdownWithHint
(
alignment:
AlignmentDirectional
.
center
,
isExpanded:
true
,
));
expect
(
tester
.
getCenter
(
find
.
text
(
hintText
)).
dx
,
388.0
);
expect
(
tester
.
getCenter
(
find
.
text
(
hintText
)).
dy
,
300.0
);
// AlignmentDirectional.topEnd
await
tester
.
pumpWidget
(
buildDropdownWithHint
(
alignment:
AlignmentDirectional
.
topEnd
,
isExpanded:
true
,
));
expect
(
tester
.
getTopRight
(
find
.
text
(
hintText
)).
dx
,
776.0
);
expect
(
tester
.
getTopRight
(
find
.
text
(
hintText
)).
dy
,
250.0
);
// AlignmentDirectional.centerEnd
await
tester
.
pumpWidget
(
buildDropdownWithHint
(
alignment:
AlignmentDirectional
.
centerEnd
,
isExpanded:
true
,
));
expect
(
tester
.
getTopRight
(
find
.
text
(
hintText
)).
dx
,
776.0
);
expect
(
tester
.
getTopRight
(
find
.
text
(
hintText
)).
dy
,
292.0
);
// AlignmentDirectional.bottomEnd
await
tester
.
pumpWidget
(
buildDropdownWithHint
(
alignment:
AlignmentDirectional
.
bottomEnd
,
isExpanded:
true
,
));
expect
(
tester
.
getBottomRight
(
find
.
text
(
hintText
)).
dx
,
776.0
);
expect
(
tester
.
getBottomRight
(
find
.
text
(
hintText
)).
dy
,
350.0
);
});
testWidgets
(
'DropdownButton hint alignment with selectedItemBuilder'
,
(
WidgetTester
tester
)
async
{
const
String
hintText
=
'hint'
;
// AlignmentDirectional.centerStart (default)
await
tester
.
pumpWidget
(
buildDropdownWithHint
(
alignment:
AlignmentDirectional
.
centerStart
,
isExpanded:
false
,
enableSelectedItemBuilder:
true
,
));
expect
(
tester
.
getTopLeft
(
find
.
text
(
hintText
)).
dx
,
348.0
);
expect
(
tester
.
getTopLeft
(
find
.
text
(
hintText
)).
dy
,
292.0
);
// AlignmentDirectional.topStart
await
tester
.
pumpWidget
(
buildDropdownWithHint
(
alignment:
AlignmentDirectional
.
topStart
,
isExpanded:
false
,
enableSelectedItemBuilder:
true
,
));
expect
(
tester
.
getTopLeft
(
find
.
text
(
hintText
)).
dx
,
348.0
);
expect
(
tester
.
getTopLeft
(
find
.
text
(
hintText
)).
dy
,
250.0
);
// AlignmentDirectional.bottomStart
await
tester
.
pumpWidget
(
buildDropdownWithHint
(
alignment:
AlignmentDirectional
.
bottomStart
,
isExpanded:
false
,
enableSelectedItemBuilder:
true
,
));
expect
(
tester
.
getBottomLeft
(
find
.
text
(
hintText
)).
dx
,
348.0
);
expect
(
tester
.
getBottomLeft
(
find
.
text
(
hintText
)).
dy
,
350.0
);
// AlignmentDirectional.center
await
tester
.
pumpWidget
(
buildDropdownWithHint
(
alignment:
AlignmentDirectional
.
center
,
hint:
const
Text
(
hintText
)),
);
isExpanded:
false
,
enableSelectedItemBuilder:
true
,
));
expect
(
tester
.
getCenter
(
find
.
text
(
hintText
)).
dx
,
388.0
);
expect
(
tester
.
getCenter
(
find
.
text
(
hintText
)).
dy
,
300.0
);
// AlignmentDirectional.topEnd
await
tester
.
pumpWidget
(
buildFrame
(
buttonKey:
buttonKey
,
mediaSize:
const
Size
(
800
,
600
),
itemHeight:
100.0
,
await
tester
.
pumpWidget
(
buildDropdownWithHint
(
alignment:
AlignmentDirectional
.
topEnd
,
isExpanded:
false
,
enableSelectedItemBuilder:
true
,
));
expect
(
tester
.
getTopRight
(
find
.
text
(
hintText
)).
dx
,
428.0
);
expect
(
tester
.
getTopRight
(
find
.
text
(
hintText
)).
dy
,
250.0
);
// AlignmentDirectional.centerEnd
await
tester
.
pumpWidget
(
buildDropdownWithHint
(
alignment:
AlignmentDirectional
.
centerEnd
,
isExpanded:
false
,
enableSelectedItemBuilder:
true
,
));
expect
(
tester
.
getTopRight
(
find
.
text
(
hintText
)).
dx
,
428.0
);
expect
(
tester
.
getTopRight
(
find
.
text
(
hintText
)).
dy
,
292.0
);
// AlignmentDirectional.bottomEnd
await
tester
.
pumpWidget
(
buildDropdownWithHint
(
alignment:
AlignmentDirectional
.
bottomEnd
,
isExpanded:
false
,
enableSelectedItemBuilder:
true
,
));
expect
(
tester
.
getTopRight
(
find
.
text
(
hintText
)).
dx
,
428.0
);
expect
(
tester
.
getTopRight
(
find
.
text
(
hintText
)).
dy
,
334.0
);
// DropdownButton with `isExpanded: true`
// AlignmentDirectional.centerStart (default)
await
tester
.
pumpWidget
(
buildDropdownWithHint
(
alignment:
AlignmentDirectional
.
centerStart
,
isExpanded:
true
,
enableSelectedItemBuilder:
true
,
));
expect
(
tester
.
getTopLeft
(
find
.
text
(
hintText
)).
dx
,
0.0
);
expect
(
tester
.
getTopLeft
(
find
.
text
(
hintText
)).
dy
,
292.0
);
// AlignmentDirectional.topStart
await
tester
.
pumpWidget
(
buildDropdownWithHint
(
alignment:
AlignmentDirectional
.
topStart
,
isExpanded:
true
,
enableSelectedItemBuilder:
true
,
));
expect
(
tester
.
getTopLeft
(
find
.
text
(
hintText
)).
dx
,
0.0
);
expect
(
tester
.
getTopLeft
(
find
.
text
(
hintText
)).
dy
,
250.0
);
// AlignmentDirectional.bottomStart
await
tester
.
pumpWidget
(
buildDropdownWithHint
(
alignment:
AlignmentDirectional
.
bottomStart
,
isExpanded:
true
,
enableSelectedItemBuilder:
true
,
));
expect
(
tester
.
getBottomLeft
(
find
.
text
(
hintText
)).
dx
,
0.0
);
expect
(
tester
.
getBottomLeft
(
find
.
text
(
hintText
)).
dy
,
350.0
);
// AlignmentDirectional.center
await
tester
.
pumpWidget
(
buildDropdownWithHint
(
alignment:
AlignmentDirectional
.
center
,
isExpanded:
true
,
enableSelectedItemBuilder:
true
,
));
expect
(
tester
.
getCenter
(
find
.
text
(
hintText
)).
dx
,
388.0
);
expect
(
tester
.
getCenter
(
find
.
text
(
hintText
)).
dy
,
300.0
);
// AlignmentDirectional.topEnd
await
tester
.
pumpWidget
(
buildDropdownWithHint
(
alignment:
AlignmentDirectional
.
topEnd
,
hint:
const
Text
(
hintText
)),
);
isExpanded:
true
,
enableSelectedItemBuilder:
true
,
));
expect
(
tester
.
getTopRight
(
find
.
text
(
hintText
)).
dx
,
776.0
);
expect
(
tester
.
getTopRight
(
find
.
text
(
hintText
)).
dy
,
250.0
);
// AlignmentDirectional.centerEnd
await
tester
.
pumpWidget
(
buildFrame
(
buttonKey:
buttonKey
,
mediaSize:
const
Size
(
800
,
600
),
itemHeight:
100.0
,
isExpanded:
true
,
await
tester
.
pumpWidget
(
buildDropdownWithHint
(
alignment:
AlignmentDirectional
.
centerEnd
,
hint:
const
Text
(
hintText
)),
);
isExpanded:
true
,
enableSelectedItemBuilder:
true
,
));
expect
(
tester
.
getTopRight
(
find
.
text
(
hintText
)).
dx
,
776.0
);
expect
(
tester
.
getTopRight
(
find
.
text
(
hintText
)).
dy
,
292.0
);
// AlignmentDirectional.bottomEnd
await
tester
.
pumpWidget
(
buildFrame
(
buttonKey:
buttonKey
,
mediaSize:
const
Size
(
800
,
600
),
itemHeight:
100.0
,
isExpanded:
true
,
await
tester
.
pumpWidget
(
buildDropdownWithHint
(
alignment:
AlignmentDirectional
.
bottomEnd
,
hint:
const
Text
(
hintText
)),
);
isExpanded:
true
,
enableSelectedItemBuilder:
true
,
));
expect
(
tester
.
getBottomRight
(
find
.
text
(
hintText
)).
dx
,
776.0
);
expect
(
tester
.
getBottomRight
(
find
.
text
(
hintText
)).
dy
,
350.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