@@ -58,7 +58,7 @@ Widget buildDropdown({
58
58
List <String >? items = menuItems,
59
59
List <Widget > Function (BuildContext )? selectedItemBuilder,
60
60
double ? itemHeight = kMinInteractiveDimension,
61
- Alignment alignment = Alignment .center ,
61
+ AlignmentDirectional alignment = AlignmentDirectional .centerStart ,
62
62
TextDirection textDirection = TextDirection .ltr,
63
63
Size ? mediaSize,
64
64
FocusNode ? focusNode,
@@ -98,6 +98,7 @@ Widget buildDropdown({
98
98
items: listItems,
99
99
selectedItemBuilder: selectedItemBuilder,
100
100
itemHeight: itemHeight,
101
+ alignment: alignment,
101
102
menuMaxHeight: menuMaxHeight,
102
103
),
103
104
);
@@ -123,6 +124,7 @@ Widget buildDropdown({
123
124
items: listItems,
124
125
selectedItemBuilder: selectedItemBuilder,
125
126
itemHeight: itemHeight,
127
+ alignment: alignment,
126
128
menuMaxHeight: menuMaxHeight,
127
129
);
128
130
}
@@ -144,7 +146,7 @@ Widget buildFrame({
144
146
List <String >? items = menuItems,
145
147
List <Widget > Function (BuildContext )? selectedItemBuilder,
146
148
double ? itemHeight = kMinInteractiveDimension,
147
- Alignment alignment = Alignment .center ,
149
+ AlignmentDirectional alignment = AlignmentDirectional .centerStart ,
148
150
TextDirection textDirection = TextDirection .ltr,
149
151
Size ? mediaSize,
150
152
FocusNode ? focusNode,
@@ -153,13 +155,14 @@ Widget buildFrame({
153
155
Color ? dropdownColor,
154
156
bool isFormField = false ,
155
157
double ? menuMaxHeight,
158
+ Alignment dropdownAlignment = Alignment .center,
156
159
}) {
157
160
return TestApp (
158
161
textDirection: textDirection,
159
162
mediaSize: mediaSize,
160
163
child: Material (
161
164
child: Align (
162
- alignment: alignment ,
165
+ alignment: dropdownAlignment ,
163
166
child: RepaintBoundary (
164
167
child: buildDropdown (
165
168
isFormField: isFormField,
@@ -183,6 +186,7 @@ Widget buildFrame({
183
186
items: items,
184
187
selectedItemBuilder: selectedItemBuilder,
185
188
itemHeight: itemHeight,
189
+ alignment: alignment,
186
190
menuMaxHeight: menuMaxHeight,
187
191
),
188
192
),
@@ -1180,19 +1184,19 @@ void main() {
1180
1184
// so that it fits within the frame.
1181
1185
1182
1186
await popUpAndDown (
1183
- buildFrame (alignment : Alignment .topLeft, value: menuItems.last, onChanged: onChanged),
1187
+ buildFrame (dropdownAlignment : Alignment .topLeft, value: menuItems.last, onChanged: onChanged),
1184
1188
);
1185
1189
expect (menuRect.topLeft, Offset .zero);
1186
1190
expect (menuRect.topRight, Offset (menuRect.width, 0.0 ));
1187
1191
1188
1192
await popUpAndDown (
1189
- buildFrame (alignment : Alignment .topCenter, value: menuItems.last, onChanged: onChanged),
1193
+ buildFrame (dropdownAlignment : Alignment .topCenter, value: menuItems.last, onChanged: onChanged),
1190
1194
);
1191
1195
expect (menuRect.topLeft, Offset (buttonRect.left, 0.0 ));
1192
1196
expect (menuRect.topRight, Offset (buttonRect.right, 0.0 ));
1193
1197
1194
1198
await popUpAndDown (
1195
- buildFrame (alignment : Alignment .topRight, value: menuItems.last, onChanged: onChanged),
1199
+ buildFrame (dropdownAlignment : Alignment .topRight, value: menuItems.last, onChanged: onChanged),
1196
1200
);
1197
1201
expect (menuRect.topLeft, Offset (800.0 - menuRect.width, 0.0 ));
1198
1202
expect (menuRect.topRight, const Offset (800.0 , 0.0 ));
@@ -1202,7 +1206,7 @@ void main() {
1202
1206
// is selected) and shifted horizontally so that it fits within the frame.
1203
1207
1204
1208
await popUpAndDown (
1205
- buildFrame (alignment : Alignment .centerLeft, value: menuItems.first, onChanged: onChanged),
1209
+ buildFrame (dropdownAlignment : Alignment .centerLeft, value: menuItems.first, onChanged: onChanged),
1206
1210
);
1207
1211
expect (menuRect.topLeft, Offset (0.0 , buttonRect.top));
1208
1212
expect (menuRect.topRight, Offset (menuRect.width, buttonRect.top));
@@ -1214,7 +1218,7 @@ void main() {
1214
1218
expect (menuRect.topRight, buttonRect.topRight);
1215
1219
1216
1220
await popUpAndDown (
1217
- buildFrame (alignment : Alignment .centerRight, value: menuItems.first, onChanged: onChanged),
1221
+ buildFrame (dropdownAlignment : Alignment .centerRight, value: menuItems.first, onChanged: onChanged),
1218
1222
);
1219
1223
expect (menuRect.topLeft, Offset (800.0 - menuRect.width, buttonRect.top));
1220
1224
expect (menuRect.topRight, Offset (800.0 , buttonRect.top));
@@ -1224,19 +1228,19 @@ void main() {
1224
1228
// so that it fits within the frame.
1225
1229
1226
1230
await popUpAndDown (
1227
- buildFrame (alignment : Alignment .bottomLeft, value: menuItems.first, onChanged: onChanged),
1231
+ buildFrame (dropdownAlignment : Alignment .bottomLeft, value: menuItems.first, onChanged: onChanged),
1228
1232
);
1229
1233
expect (menuRect.bottomLeft, const Offset (0.0 , 600.0 ));
1230
1234
expect (menuRect.bottomRight, Offset (menuRect.width, 600.0 ));
1231
1235
1232
1236
await popUpAndDown (
1233
- buildFrame (alignment : Alignment .bottomCenter, value: menuItems.first, onChanged: onChanged),
1237
+ buildFrame (dropdownAlignment : Alignment .bottomCenter, value: menuItems.first, onChanged: onChanged),
1234
1238
);
1235
1239
expect (menuRect.bottomLeft, Offset (buttonRect.left, 600.0 ));
1236
1240
expect (menuRect.bottomRight, Offset (buttonRect.right, 600.0 ));
1237
1241
1238
1242
await popUpAndDown (
1239
- buildFrame (alignment : Alignment .bottomRight, value: menuItems.first, onChanged: onChanged),
1243
+ buildFrame (dropdownAlignment : Alignment .bottomRight, value: menuItems.first, onChanged: onChanged),
1240
1244
);
1241
1245
expect (menuRect.bottomLeft, Offset (800.0 - menuRect.width, 600.0 ));
1242
1246
expect (menuRect.bottomRight, const Offset (800.0 , 600.0 ));
@@ -3681,4 +3685,158 @@ void main() {
3681
3685
..rrect (rrect: const RRect .fromLTRBXY (0.0 , 0.0 , 800.0 , 208.0 , radius, radius)),
3682
3686
);
3683
3687
});
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
+ });
3684
3842
}
0 commit comments