@@ -718,6 +718,64 @@ void main() {
718
718
expect (box.size.width, customWidth);
719
719
});
720
720
721
+ testWidgets ('The width is determined by the menu entries' , (WidgetTester tester) async {
722
+ const double entryLabelWidth = 100 ;
723
+
724
+ await tester.pumpWidget (
725
+ const MaterialApp (
726
+ home: Scaffold (
727
+ body: DropdownMenu <int >(
728
+ dropdownMenuEntries: < DropdownMenuEntry <int >> [
729
+ DropdownMenuEntry <int >(
730
+ value: 0 ,
731
+ label: 'Flutter' ,
732
+ labelWidget: SizedBox (width: entryLabelWidth),
733
+ ),
734
+ ],
735
+ ),
736
+ ),
737
+ ),
738
+ );
739
+
740
+ final double width = tester.getSize (find.byType (DropdownMenu <int >)).width;
741
+ const double menuEntryPadding = 24.0 ; // See _kDefaultHorizontalPadding.
742
+ const double leadingWidth = 16.0 ;
743
+ const double trailingWidth = 56.0 ;
744
+
745
+ expect (width, entryLabelWidth + leadingWidth + trailingWidth + menuEntryPadding);
746
+ });
747
+
748
+ testWidgets ('The width is determined by the label when it is longer than menu entries' , (
749
+ WidgetTester tester,
750
+ ) async {
751
+ const double labelWidth = 120 ;
752
+ const double entryLabelWidth = 100 ;
753
+
754
+ await tester.pumpWidget (
755
+ const MaterialApp (
756
+ home: Scaffold (
757
+ body: DropdownMenu <int >(
758
+ label: SizedBox (width: labelWidth),
759
+ dropdownMenuEntries: < DropdownMenuEntry <int >> [
760
+ DropdownMenuEntry <int >(
761
+ value: 0 ,
762
+ label: 'Flutter' ,
763
+ labelWidget: SizedBox (width: entryLabelWidth),
764
+ ),
765
+ ],
766
+ ),
767
+ ),
768
+ ),
769
+ );
770
+
771
+ final double width = tester.getSize (find.byType (DropdownMenu <int >)).width;
772
+ const double leadingWidth = 16.0 ;
773
+ const double trailingWidth = 56.0 ;
774
+ const double labelPadding = 8.0 ; // See RenderEditable.floatingCursorAddedMargin.
775
+
776
+ expect (width, labelWidth + labelPadding + leadingWidth + trailingWidth);
777
+ });
778
+
721
779
testWidgets ('The width of MenuAnchor respects MenuAnchor.expandedInsets' , (
722
780
WidgetTester tester,
723
781
) async {
@@ -962,7 +1020,7 @@ void main() {
962
1020
// Default text field (without leading icon).
963
1021
await tester.pumpWidget (buildTest (themeData, menuChildren, label: const Text ('label' )));
964
1022
965
- final Finder label = find.text ('label' );
1023
+ final Finder label = find.text ('label' ).first ;
966
1024
final Offset labelTopLeft = tester.getTopLeft (label);
967
1025
968
1026
await tester.tap (find.byType (DropdownMenu <TestMenu >));
@@ -985,7 +1043,7 @@ void main() {
985
1043
986
1044
final Finder leadingIcon = find.widgetWithIcon (SizedBox , Icons .search).last;
987
1045
final double iconWidth = tester.getSize (leadingIcon).width;
988
- final Finder updatedLabel = find.text ('label' );
1046
+ final Finder updatedLabel = find.text ('label' ).first ;
989
1047
final Offset updatedLabelTopLeft = tester.getTopLeft (updatedLabel);
990
1048
991
1049
await tester.tap (find.byType (DropdownMenu <TestMenu >));
@@ -1009,7 +1067,7 @@ void main() {
1009
1067
1010
1068
final Finder largeLeadingIcon = find.widgetWithIcon (SizedBox , Icons .search).last;
1011
1069
final double largeIconWidth = tester.getSize (largeLeadingIcon).width;
1012
- final Finder updatedLabel1 = find.text ('label' );
1070
+ final Finder updatedLabel1 = find.text ('label' ).first ;
1013
1071
final Offset updatedLabelTopLeft1 = tester.getTopLeft (updatedLabel1);
1014
1072
1015
1073
await tester.tap (find.byType (DropdownMenu <TestMenu >));
@@ -1040,7 +1098,7 @@ void main() {
1040
1098
),
1041
1099
);
1042
1100
1043
- final Finder label = find.text ('label' );
1101
+ final Finder label = find.text ('label' ).first ;
1044
1102
final Offset labelTopRight = tester.getTopRight (label);
1045
1103
1046
1104
await tester.tap (find.byType (DropdownMenu <TestMenu >));
@@ -1072,7 +1130,7 @@ void main() {
1072
1130
final Finder leadingIcon = find.widgetWithIcon (SizedBox , Icons .search).last;
1073
1131
final double iconWidth = tester.getSize (leadingIcon).width;
1074
1132
final Offset dropdownMenuTopRight = tester.getTopRight (find.byType (DropdownMenu <TestMenu >));
1075
- final Finder updatedLabel = find.text ('label' );
1133
+ final Finder updatedLabel = find.text ('label' ).first ;
1076
1134
final Offset updatedLabelTopRight = tester.getTopRight (updatedLabel);
1077
1135
1078
1136
await tester.tap (find.byType (DropdownMenu <TestMenu >));
@@ -1110,7 +1168,7 @@ void main() {
1110
1168
final Offset updatedDropdownMenuTopRight = tester.getTopRight (
1111
1169
find.byType (DropdownMenu <TestMenu >),
1112
1170
);
1113
- final Finder updatedLabel1 = find.text ('label' );
1171
+ final Finder updatedLabel1 = find.text ('label' ).first ;
1114
1172
final Offset updatedLabelTopRight1 = tester.getTopRight (updatedLabel1);
1115
1173
1116
1174
await tester.tap (find.byType (DropdownMenu <TestMenu >));
0 commit comments