@@ -271,15 +271,15 @@ void main() {
271
271
);
272
272
expect (
273
273
tester.getRect (find.widgetWithText (MenuItemButton , TestMenu .subMenu10.label)),
274
- equals (const Rect .fromLTRB (265.0 , 40 .0 , 467.0 , 80 .0 )),
274
+ equals (const Rect .fromLTRB (265.0 , 48 .0 , 467.0 , 88 .0 )),
275
275
);
276
276
expect (
277
277
tester.getRect (
278
278
find
279
279
.ancestor (of: find.text (TestMenu .subMenu10.label), matching: find.byType (Material ))
280
280
.at (1 ),
281
281
),
282
- equals (const Rect .fromLTRB (265.0 , 40.0 , 467.0 , 160 .0 )),
282
+ equals (const Rect .fromLTRB (265.0 , 40.0 , 467.0 , 176 .0 )),
283
283
);
284
284
285
285
await tester.pumpWidget (Container ());
@@ -295,7 +295,7 @@ void main() {
295
295
// 590 = 695 - 105
296
296
expect (
297
297
tester.getRect (find.byType (MenuBar )),
298
- equals (const Rect .fromLTRB (105.0 , 0.0 , 695.0 , 72 .0 )),
298
+ equals (const Rect .fromLTRB (105.0 , 0.0 , 695.0 , 56 .0 )),
299
299
);
300
300
301
301
// Open and make sure things are the right size.
@@ -304,23 +304,19 @@ void main() {
304
304
305
305
expect (
306
306
tester.getRect (find.byType (MenuBar )),
307
- equals (const Rect .fromLTRB (105.0 , 0.0 , 695.0 , 72.0 )),
308
- );
309
- expect (
310
- tester.getRect (find.byType (MenuBar )),
311
- equals (const Rect .fromLTRB (105.0 , 0.0 , 695.0 , 72.0 )),
307
+ equals (const Rect .fromLTRB (105.0 , 0.0 , 695.0 , 56.0 )),
312
308
);
313
309
expect (
314
310
tester.getRect (find.widgetWithText (MenuItemButton , TestMenu .subMenu10.label)),
315
- equals (const Rect .fromLTRB (257.0 , 80 .0 , 491.0 , 136 .0 )),
311
+ equals (const Rect .fromLTRB (257.0 , 64 .0 , 491.0 , 120 .0 )),
316
312
);
317
313
expect (
318
314
tester.getRect (
319
315
find
320
316
.ancestor (of: find.text (TestMenu .subMenu10.label), matching: find.byType (Material ))
321
317
.at (1 ),
322
318
),
323
- equals (const Rect .fromLTRB (249.0 , 64 .0 , 499.0 , 264 .0 )),
319
+ equals (const Rect .fromLTRB (249.0 , 56 .0 , 499.0 , 240 .0 )),
324
320
);
325
321
});
326
322
@@ -3803,8 +3799,8 @@ void main() {
3803
3799
collectSubmenuRects (),
3804
3800
equals (const < Rect > [
3805
3801
Rect .fromLTRB (161.0 , 0.0 , 639.0 , 40.0 ),
3806
- Rect .fromLTRB (265.0 , 40.0 , 467.0 , 160 .0 ),
3807
- Rect .fromLTRB (467.0 , 80.0 , 707.0 , 240 .0 ),
3802
+ Rect .fromLTRB (265.0 , 40.0 , 467.0 , 176 .0 ),
3803
+ Rect .fromLTRB (467.0 , 80.0 , 707.0 , 256 .0 ),
3808
3804
]),
3809
3805
);
3810
3806
});
@@ -3819,8 +3815,8 @@ void main() {
3819
3815
collectSubmenuRects (),
3820
3816
equals (const < Rect > [
3821
3817
Rect .fromLTRB (161.0 , 0.0 , 639.0 , 40.0 ),
3822
- Rect .fromLTRB (333.0 , 40.0 , 535.0 , 160 .0 ),
3823
- Rect .fromLTRB (93.0 , 80.0 , 333.0 , 240 .0 ),
3818
+ Rect .fromLTRB (333.0 , 40.0 , 535.0 , 176 .0 ),
3819
+ Rect .fromLTRB (93.0 , 80.0 , 333.0 , 256 .0 ),
3824
3820
]),
3825
3821
);
3826
3822
});
@@ -3943,6 +3939,103 @@ void main() {
3943
3939
},
3944
3940
);
3945
3941
3942
+ // Regression test for https://github.com/flutter/flutter/issues/171608
3943
+ testWidgets ('Menu vertical padding should not be reduced with compact visual density' , (
3944
+ WidgetTester tester,
3945
+ ) async {
3946
+ // Helper function to get menu padding by measuring first/last items.
3947
+ (double , double ) getMenuPadding () {
3948
+ // Find any menu items that are available.
3949
+ final Finder menuItems = find.byType (SubmenuButton );
3950
+ if (menuItems.evaluate ().length < 2 ) {
3951
+ return (0.0 , 0.0 );
3952
+ }
3953
+
3954
+ final Rect firstItem = tester.getRect (menuItems.first);
3955
+ final Rect lastItem = tester.getRect (menuItems.last);
3956
+ final Rect menuPanel = tester.getRect (find.byType (Material ).last);
3957
+
3958
+ final double topPadding = firstItem.top - menuPanel.top;
3959
+ final double bottomPadding = menuPanel.bottom - lastItem.bottom;
3960
+ return (topPadding, bottomPadding);
3961
+ }
3962
+
3963
+ Future <void > buildSimpleMenuAnchor (
3964
+ TextDirection textDirection, {
3965
+ VisualDensity visualDensity = VisualDensity .standard,
3966
+ }) async {
3967
+ await tester.pumpWidget (
3968
+ MaterialApp (
3969
+ theme: ThemeData (visualDensity: visualDensity),
3970
+ home: Directionality (
3971
+ textDirection: textDirection,
3972
+ child: Scaffold (
3973
+ body: MenuAnchor (
3974
+ style: const MenuStyle (
3975
+ padding: WidgetStatePropertyAll <EdgeInsets >(
3976
+ EdgeInsets .symmetric (vertical: 12 , horizontal: 4 ),
3977
+ ),
3978
+ ),
3979
+ menuChildren: const < Widget > [
3980
+ DecoratedBox (
3981
+ decoration: BoxDecoration (color: Colors .blue),
3982
+ child: Text ('Text 1' ),
3983
+ ),
3984
+ DecoratedBox (
3985
+ decoration: BoxDecoration (color: Colors .blue),
3986
+ child: Text ('Text 2' ),
3987
+ ),
3988
+ ],
3989
+ builder: (BuildContext context, MenuController controller, Widget ? child) {
3990
+ return TextButton (
3991
+ onPressed: () {
3992
+ if (controller.isOpen) {
3993
+ controller.close ();
3994
+ } else {
3995
+ controller.open ();
3996
+ }
3997
+ },
3998
+ child: const Text ('OPEN MENU' ),
3999
+ );
4000
+ },
4001
+ ),
4002
+ ),
4003
+ ),
4004
+ ),
4005
+ );
4006
+
4007
+ await tester.tap (find.text ('OPEN MENU' ));
4008
+ await tester.pump ();
4009
+ }
4010
+
4011
+ // Pump widget with standard visual density.
4012
+ await buildSimpleMenuAnchor (TextDirection .ltr);
4013
+
4014
+ final (double topStandard, double bottomStandard) = getMenuPadding ();
4015
+
4016
+ // Pump widget with compact visual density.
4017
+ await buildSimpleMenuAnchor (TextDirection .ltr, visualDensity: VisualDensity .compact);
4018
+
4019
+ final (double topCompact, double bottomCompact) = getMenuPadding ();
4020
+
4021
+ // Compare standard vs compact padding.
4022
+ expect (
4023
+ topCompact,
4024
+ equals (topStandard),
4025
+ reason:
4026
+ 'Compact visual density should not change top padding. '
4027
+ 'Standard: $topStandard , Compact: $topCompact ' ,
4028
+ );
4029
+
4030
+ expect (
4031
+ bottomCompact,
4032
+ equals (bottomStandard),
4033
+ reason:
4034
+ 'Compact visual density should not change bottom padding. '
4035
+ 'Standard: $bottomStandard , Compact: $bottomCompact ' ,
4036
+ );
4037
+ });
4038
+
3946
4039
group ('LocalizedShortcutLabeler' , () {
3947
4040
testWidgets ('getShortcutLabel returns the right labels' , (WidgetTester tester) async {
3948
4041
String expectedMeta;
0 commit comments