@@ -58,7 +58,7 @@ Widget buildDropdown({
5858 List <String >? items = menuItems,
5959 List <Widget > Function (BuildContext )? selectedItemBuilder,
6060 double ? itemHeight = kMinInteractiveDimension,
61- Alignment alignment = Alignment .center ,
61+ AlignmentDirectional alignment = AlignmentDirectional .centerStart ,
6262 TextDirection textDirection = TextDirection .ltr,
6363 Size ? mediaSize,
6464 FocusNode ? focusNode,
@@ -98,6 +98,7 @@ Widget buildDropdown({
9898 items: listItems,
9999 selectedItemBuilder: selectedItemBuilder,
100100 itemHeight: itemHeight,
101+ alignment: alignment,
101102 menuMaxHeight: menuMaxHeight,
102103 ),
103104 );
@@ -123,6 +124,7 @@ Widget buildDropdown({
123124 items: listItems,
124125 selectedItemBuilder: selectedItemBuilder,
125126 itemHeight: itemHeight,
127+ alignment: alignment,
126128 menuMaxHeight: menuMaxHeight,
127129 );
128130}
@@ -144,7 +146,7 @@ Widget buildFrame({
144146 List <String >? items = menuItems,
145147 List <Widget > Function (BuildContext )? selectedItemBuilder,
146148 double ? itemHeight = kMinInteractiveDimension,
147- Alignment alignment = Alignment .center ,
149+ AlignmentDirectional alignment = AlignmentDirectional .centerStart ,
148150 TextDirection textDirection = TextDirection .ltr,
149151 Size ? mediaSize,
150152 FocusNode ? focusNode,
@@ -153,13 +155,14 @@ Widget buildFrame({
153155 Color ? dropdownColor,
154156 bool isFormField = false ,
155157 double ? menuMaxHeight,
158+ Alignment dropdownAlignment = Alignment .center,
156159}) {
157160 return TestApp (
158161 textDirection: textDirection,
159162 mediaSize: mediaSize,
160163 child: Material (
161164 child: Align (
162- alignment: alignment ,
165+ alignment: dropdownAlignment ,
163166 child: RepaintBoundary (
164167 child: buildDropdown (
165168 isFormField: isFormField,
@@ -183,6 +186,7 @@ Widget buildFrame({
183186 items: items,
184187 selectedItemBuilder: selectedItemBuilder,
185188 itemHeight: itemHeight,
189+ alignment: alignment,
186190 menuMaxHeight: menuMaxHeight,
187191 ),
188192 ),
@@ -1180,19 +1184,19 @@ void main() {
11801184 // so that it fits within the frame.
11811185
11821186 await popUpAndDown (
1183- buildFrame (alignment : Alignment .topLeft, value: menuItems.last, onChanged: onChanged),
1187+ buildFrame (dropdownAlignment : Alignment .topLeft, value: menuItems.last, onChanged: onChanged),
11841188 );
11851189 expect (menuRect.topLeft, Offset .zero);
11861190 expect (menuRect.topRight, Offset (menuRect.width, 0.0 ));
11871191
11881192 await popUpAndDown (
1189- buildFrame (alignment : Alignment .topCenter, value: menuItems.last, onChanged: onChanged),
1193+ buildFrame (dropdownAlignment : Alignment .topCenter, value: menuItems.last, onChanged: onChanged),
11901194 );
11911195 expect (menuRect.topLeft, Offset (buttonRect.left, 0.0 ));
11921196 expect (menuRect.topRight, Offset (buttonRect.right, 0.0 ));
11931197
11941198 await popUpAndDown (
1195- buildFrame (alignment : Alignment .topRight, value: menuItems.last, onChanged: onChanged),
1199+ buildFrame (dropdownAlignment : Alignment .topRight, value: menuItems.last, onChanged: onChanged),
11961200 );
11971201 expect (menuRect.topLeft, Offset (800.0 - menuRect.width, 0.0 ));
11981202 expect (menuRect.topRight, const Offset (800.0 , 0.0 ));
@@ -1202,7 +1206,7 @@ void main() {
12021206 // is selected) and shifted horizontally so that it fits within the frame.
12031207
12041208 await popUpAndDown (
1205- buildFrame (alignment : Alignment .centerLeft, value: menuItems.first, onChanged: onChanged),
1209+ buildFrame (dropdownAlignment : Alignment .centerLeft, value: menuItems.first, onChanged: onChanged),
12061210 );
12071211 expect (menuRect.topLeft, Offset (0.0 , buttonRect.top));
12081212 expect (menuRect.topRight, Offset (menuRect.width, buttonRect.top));
@@ -1214,7 +1218,7 @@ void main() {
12141218 expect (menuRect.topRight, buttonRect.topRight);
12151219
12161220 await popUpAndDown (
1217- buildFrame (alignment : Alignment .centerRight, value: menuItems.first, onChanged: onChanged),
1221+ buildFrame (dropdownAlignment : Alignment .centerRight, value: menuItems.first, onChanged: onChanged),
12181222 );
12191223 expect (menuRect.topLeft, Offset (800.0 - menuRect.width, buttonRect.top));
12201224 expect (menuRect.topRight, Offset (800.0 , buttonRect.top));
@@ -1224,19 +1228,19 @@ void main() {
12241228 // so that it fits within the frame.
12251229
12261230 await popUpAndDown (
1227- buildFrame (alignment : Alignment .bottomLeft, value: menuItems.first, onChanged: onChanged),
1231+ buildFrame (dropdownAlignment : Alignment .bottomLeft, value: menuItems.first, onChanged: onChanged),
12281232 );
12291233 expect (menuRect.bottomLeft, const Offset (0.0 , 600.0 ));
12301234 expect (menuRect.bottomRight, Offset (menuRect.width, 600.0 ));
12311235
12321236 await popUpAndDown (
1233- buildFrame (alignment : Alignment .bottomCenter, value: menuItems.first, onChanged: onChanged),
1237+ buildFrame (dropdownAlignment : Alignment .bottomCenter, value: menuItems.first, onChanged: onChanged),
12341238 );
12351239 expect (menuRect.bottomLeft, Offset (buttonRect.left, 600.0 ));
12361240 expect (menuRect.bottomRight, Offset (buttonRect.right, 600.0 ));
12371241
12381242 await popUpAndDown (
1239- buildFrame (alignment : Alignment .bottomRight, value: menuItems.first, onChanged: onChanged),
1243+ buildFrame (dropdownAlignment : Alignment .bottomRight, value: menuItems.first, onChanged: onChanged),
12401244 );
12411245 expect (menuRect.bottomLeft, Offset (800.0 - menuRect.width, 600.0 ));
12421246 expect (menuRect.bottomRight, const Offset (800.0 , 600.0 ));
@@ -3681,4 +3685,158 @@ void main() {
36813685 ..rrect (rrect: const RRect .fromLTRBXY (0.0 , 0.0 , 800.0 , 208.0 , radius, radius)),
36823686 );
36833687 });
3688+
3689+ testWidgets ('DropdownButton hint alignment' , (WidgetTester tester) async {
3690+ final Key buttonKey = UniqueKey ();
3691+ const String hintText = 'hint' ;
3692+
3693+ // DropdownButton with `isExpanded: false` (default)
3694+ // AlignmentDirectional.centerStart (default)
3695+ await tester.pumpWidget (buildFrame (
3696+ buttonKey: buttonKey,
3697+ mediaSize: const Size (800 , 600 ),
3698+ itemHeight: 100.0 ,
3699+ hint: const Text (hintText)),
3700+ );
3701+ expect (tester.getTopLeft (find.text (hintText)).dx, 348.0 );
3702+ expect (tester.getTopLeft (find.text (hintText)).dy, 292.0 );
3703+ // AlignmentDirectional.topStart
3704+ await tester.pumpWidget (buildFrame (
3705+ buttonKey: buttonKey,
3706+ mediaSize: const Size (800 , 600 ),
3707+ alignment: AlignmentDirectional .topStart,
3708+ itemHeight: 100.0 ,
3709+ hint: const Text (hintText)),
3710+ );
3711+ expect (tester.getTopLeft (find.text (hintText)).dx, 348.0 );
3712+ expect (tester.getTopLeft (find.text (hintText)).dy, 250.0 );
3713+ // AlignmentDirectional.bottomStart
3714+ await tester.pumpWidget (buildFrame (
3715+ buttonKey: buttonKey,
3716+ mediaSize: const Size (800 , 600 ),
3717+ alignment: AlignmentDirectional .bottomStart,
3718+ itemHeight: 100.0 ,
3719+ hint: const Text (hintText)),
3720+ );
3721+ expect (tester.getBottomLeft (find.text (hintText)).dx, 348.0 );
3722+ expect (tester.getBottomLeft (find.text (hintText)).dy, 350.0 );
3723+ // AlignmentDirectional.center
3724+ await tester.pumpWidget (buildFrame (
3725+ buttonKey: buttonKey,
3726+ mediaSize: const Size (800 , 600 ),
3727+ alignment: AlignmentDirectional .center,
3728+ itemHeight: 100.0 ,
3729+ hint: const Text (hintText)),
3730+ );
3731+ expect (tester.getCenter (find.text (hintText)).dx, 388.0 );
3732+ expect (tester.getCenter (find.text (hintText)).dy, 300.0 );
3733+ // AlignmentDirectional.topEnd
3734+ await tester.pumpWidget (buildFrame (
3735+ buttonKey: buttonKey,
3736+ mediaSize: const Size (800 , 600 ),
3737+ alignment: AlignmentDirectional .topEnd,
3738+ itemHeight: 100.0 ,
3739+ hint: const Text (hintText)),
3740+ );
3741+ expect (tester.getTopRight (find.text (hintText)).dx, 428.0 );
3742+ expect (tester.getTopRight (find.text (hintText)).dy, 250.0 );
3743+ // AlignmentDirectional.centerEnd
3744+ await tester.pumpWidget (buildFrame (
3745+ buttonKey: buttonKey,
3746+ mediaSize: const Size (800 , 600 ),
3747+ alignment: AlignmentDirectional .centerEnd,
3748+ itemHeight: 100.0 ,
3749+ hint: const Text (hintText)),
3750+ );
3751+ expect (tester.getTopRight (find.text (hintText)).dx, 428.0 );
3752+ expect (tester.getTopRight (find.text (hintText)).dy, 292.0 );
3753+ // AlignmentDirectional.topEnd
3754+ await tester.pumpWidget (buildFrame (
3755+ buttonKey: buttonKey,
3756+ mediaSize: const Size (800 , 600 ),
3757+ alignment: AlignmentDirectional .bottomEnd,
3758+ itemHeight: 100.0 ,
3759+ hint: const Text (hintText)),
3760+ );
3761+ expect (tester.getTopRight (find.text (hintText)).dx, 428.0 );
3762+ expect (tester.getTopRight (find.text (hintText)).dy, 334.0 );
3763+
3764+ // DropdownButton with `isExpanded: true`
3765+ // AlignmentDirectional.centerStart (default)
3766+ await tester.pumpWidget (buildFrame (
3767+ buttonKey: buttonKey,
3768+ mediaSize: const Size (800 , 600 ),
3769+ itemHeight: 100.0 ,
3770+ isExpanded: true ,
3771+ hint: const Text (hintText)),
3772+ );
3773+ expect (tester.getTopLeft (find.text (hintText)).dx, 0.0 );
3774+ expect (tester.getTopLeft (find.text (hintText)).dy, 292.0 );
3775+ // AlignmentDirectional.topStart
3776+ await tester.pumpWidget (buildFrame (
3777+ buttonKey: buttonKey,
3778+ mediaSize: const Size (800 , 600 ),
3779+ itemHeight: 100.0 ,
3780+ isExpanded: true ,
3781+ alignment: AlignmentDirectional .topStart,
3782+ hint: const Text (hintText)),
3783+ );
3784+ expect (tester.getTopLeft (find.text (hintText)).dx, 0.0 );
3785+ expect (tester.getTopLeft (find.text (hintText)).dy, 250.0 );
3786+ // AlignmentDirectional.bottomStart
3787+ await tester.pumpWidget (buildFrame (
3788+ buttonKey: buttonKey,
3789+ mediaSize: const Size (800 , 600 ),
3790+ itemHeight: 100.0 ,
3791+ isExpanded: true ,
3792+ alignment: AlignmentDirectional .bottomStart,
3793+ hint: const Text (hintText)),
3794+ );
3795+ expect (tester.getBottomLeft (find.text (hintText)).dx, 0.0 );
3796+ expect (tester.getBottomLeft (find.text (hintText)).dy, 350.0 );
3797+ // AlignmentDirectional.center
3798+ await tester.pumpWidget (buildFrame (
3799+ buttonKey: buttonKey,
3800+ mediaSize: const Size (800 , 600 ),
3801+ itemHeight: 100.0 ,
3802+ isExpanded: true ,
3803+ alignment: AlignmentDirectional .center,
3804+ hint: const Text (hintText)),
3805+ );
3806+ expect (tester.getCenter (find.text (hintText)).dx, 388.0 );
3807+ expect (tester.getCenter (find.text (hintText)).dy, 300.0 );
3808+ // AlignmentDirectional.topEnd
3809+ await tester.pumpWidget (buildFrame (
3810+ buttonKey: buttonKey,
3811+ mediaSize: const Size (800 , 600 ),
3812+ itemHeight: 100.0 ,
3813+ isExpanded: true ,
3814+ alignment: AlignmentDirectional .topEnd,
3815+ hint: const Text (hintText)),
3816+ );
3817+ expect (tester.getTopRight (find.text (hintText)).dx, 776.0 );
3818+ expect (tester.getTopRight (find.text (hintText)).dy, 250.0 );
3819+ // AlignmentDirectional.centerEnd
3820+ await tester.pumpWidget (buildFrame (
3821+ buttonKey: buttonKey,
3822+ mediaSize: const Size (800 , 600 ),
3823+ itemHeight: 100.0 ,
3824+ isExpanded: true ,
3825+ alignment: AlignmentDirectional .centerEnd,
3826+ hint: const Text (hintText)),
3827+ );
3828+ expect (tester.getTopRight (find.text (hintText)).dx, 776.0 );
3829+ expect (tester.getTopRight (find.text (hintText)).dy, 292.0 );
3830+ // AlignmentDirectional.bottomEnd
3831+ await tester.pumpWidget (buildFrame (
3832+ buttonKey: buttonKey,
3833+ mediaSize: const Size (800 , 600 ),
3834+ itemHeight: 100.0 ,
3835+ isExpanded: true ,
3836+ alignment: AlignmentDirectional .bottomEnd,
3837+ hint: const Text (hintText)),
3838+ );
3839+ expect (tester.getBottomRight (find.text (hintText)).dx, 776.0 );
3840+ expect (tester.getBottomRight (find.text (hintText)).dy, 350.0 );
3841+ });
36843842}
0 commit comments