@@ -4301,8 +4301,77 @@ void main() {
4301
4301
4302
4302
expect (tester.takeException (), isNull);
4303
4303
expect (tester.getSize (findMenuItemButton (menuChildren.first.label)).width, 150.0 );
4304
+
4305
+ // The overwrite of menuStyle is different when a width is provided but maximumSize is not,
4306
+ // So it needs to be tested separately.
4307
+ await tester.pumpWidget (
4308
+ MaterialApp (
4309
+ home: Scaffold (
4310
+ body: DropdownMenu <TestMenu >(
4311
+ width: 200.0 ,
4312
+ dropdownMenuEntries: menuChildren,
4313
+ menuStyle: const MenuStyle (),
4314
+ ),
4315
+ ),
4316
+ ),
4317
+ );
4318
+
4319
+ await tester.tap (find.byType (TextField ));
4320
+ await tester.pumpAndSettle ();
4321
+
4322
+ expect (tester.getSize (findMenuItemButton (menuChildren.first.label)).width, 200.0 );
4304
4323
});
4305
4324
4325
+ testWidgets (
4326
+ 'ensure items are constrained to intrinsic size of DropdownMenu (width or anchor) when no maximumSize' ,
4327
+ (WidgetTester tester) async {
4328
+ const String shortLabel = 'Male' ;
4329
+ await tester.pumpWidget (
4330
+ const MaterialApp (
4331
+ home: Scaffold (
4332
+ body: DropdownMenu <int >(
4333
+ width: 200 ,
4334
+ dropdownMenuEntries: < DropdownMenuEntry <int >> [
4335
+ DropdownMenuEntry <int >(value: 0 , label: shortLabel),
4336
+ ],
4337
+ menuStyle: MenuStyle (),
4338
+ ),
4339
+ ),
4340
+ ),
4341
+ );
4342
+
4343
+ await tester.tap (find.byType (TextField ));
4344
+ await tester.pumpAndSettle ();
4345
+
4346
+ expect (tester.getSize (findMenuItemButton (shortLabel)).width, 200 );
4347
+
4348
+ // Use expandedInsets to anchor the TextField to the same size as the parent.
4349
+ await tester.pumpWidget (
4350
+ const MaterialApp (
4351
+ home: Scaffold (
4352
+ body: SizedBox (
4353
+ width: double .infinity,
4354
+ child: DropdownMenu <int >(
4355
+ expandedInsets: EdgeInsets .symmetric (horizontal: 20 ),
4356
+ dropdownMenuEntries: < DropdownMenuEntry <int >> [
4357
+ DropdownMenuEntry <int >(value: 0 , label: shortLabel),
4358
+ ],
4359
+ menuStyle: MenuStyle (),
4360
+ ),
4361
+ ),
4362
+ ),
4363
+ ),
4364
+ );
4365
+
4366
+ await tester.tap (find.byType (TextField ));
4367
+ await tester.pumpAndSettle ();
4368
+
4369
+ expect (tester.takeException (), isNull);
4370
+ // Default width is 800, so the expected width is 800 - padding (20 + 20).
4371
+ expect (tester.getSize (findMenuItemButton (shortLabel)).width, 760.0 );
4372
+ },
4373
+ );
4374
+
4306
4375
// Regression test for https://github.com/flutter/flutter/issues/164905.
4307
4376
testWidgets ('ensure exclude semantics for trailing button' , (WidgetTester tester) async {
4308
4377
final SemanticsTester semantics = SemanticsTester (tester);
0 commit comments