Skip to content

Commit 34b8cef

Browse files
authored
Revert "feat: added custom padding in PopupMenuButton (flutter#96657)" (flutter#96781)
1 parent a2ac0e3 commit 34b8cef

File tree

4 files changed

+6
-126
lines changed

4 files changed

+6
-126
lines changed

packages/flutter/lib/src/material/popup_menu.dart

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -528,12 +528,10 @@ class _PopupMenu<T> extends StatelessWidget {
528528
Key? key,
529529
required this.route,
530530
required this.semanticLabel,
531-
this.padding,
532531
}) : super(key: key);
533532

534533
final _PopupMenuRoute<T> route;
535534
final String? semanticLabel;
536-
final EdgeInsetsGeometry? padding;
537535

538536
@override
539537
Widget build(BuildContext context) {
@@ -585,7 +583,9 @@ class _PopupMenu<T> extends StatelessWidget {
585583
explicitChildNodes: true,
586584
label: semanticLabel,
587585
child: SingleChildScrollView(
588-
padding: padding,
586+
padding: const EdgeInsets.symmetric(
587+
vertical: _kMenuVerticalPadding,
588+
),
589589
child: ListBody(children: children),
590590
),
591591
),
@@ -727,7 +727,6 @@ class _PopupMenuRoute<T> extends PopupRoute<T> {
727727
_PopupMenuRoute({
728728
required this.position,
729729
required this.items,
730-
this.padding,
731730
this.initialValue,
732731
this.elevation,
733732
required this.barrierLabel,
@@ -741,7 +740,6 @@ class _PopupMenuRoute<T> extends PopupRoute<T> {
741740
final List<PopupMenuEntry<T>> items;
742741
final List<Size?> itemSizes;
743742
final T? initialValue;
744-
final EdgeInsetsGeometry? padding;
745743
final double? elevation;
746744
final String? semanticLabel;
747745
final ShapeBorder? shape;
@@ -780,7 +778,7 @@ class _PopupMenuRoute<T> extends PopupRoute<T> {
780778
}
781779
}
782780

783-
final Widget menu = _PopupMenu<T>(padding: padding, route: this, semanticLabel: semanticLabel);
781+
final Widget menu = _PopupMenu<T>(route: this, semanticLabel: semanticLabel);
784782
final MediaQueryData mediaQuery = MediaQuery.of(context);
785783
return MediaQuery.removePadding(
786784
context: context,
@@ -852,11 +850,6 @@ class _PopupMenuRoute<T> extends PopupRoute<T> {
852850
/// label is not provided, it will default to
853851
/// [MaterialLocalizations.popupMenuLabel].
854852
///
855-
/// The `padding` argument is used to add empty space around the outside
856-
/// of the popup menu. If this property is not provided, then [PopupMenuThemeData.padding]
857-
/// is used. If [PopupMenuThemeData.padding] is also null, then
858-
/// EdgeInsets.symmetric(vertical: 8.0) is used.
859-
///
860853
/// See also:
861854
///
862855
/// * [PopupMenuItem], a popup menu entry for a single value.
@@ -871,7 +864,6 @@ Future<T?> showMenu<T>({
871864
required RelativeRect position,
872865
required List<PopupMenuEntry<T>> items,
873866
T? initialValue,
874-
EdgeInsetsGeometry? padding,
875867
double? elevation,
876868
String? semanticLabel,
877869
ShapeBorder? shape,
@@ -900,7 +892,6 @@ Future<T?> showMenu<T>({
900892
position: position,
901893
items: items,
902894
initialValue: initialValue,
903-
padding: padding,
904895
elevation: elevation,
905896
semanticLabel: semanticLabel,
906897
barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
@@ -993,7 +984,6 @@ class PopupMenuButton<T> extends StatefulWidget {
993984
this.tooltip,
994985
this.elevation,
995986
this.padding = const EdgeInsets.all(8.0),
996-
this.menuPadding,
997987
this.child,
998988
this.icon,
999989
this.iconSize,
@@ -1088,14 +1078,6 @@ class PopupMenuButton<T> extends StatefulWidget {
10881078
/// Theme.of(context).cardColor is used.
10891079
final Color? color;
10901080

1091-
/// If provided, menu padding is used for empty space around the outside
1092-
/// of the popup menu.
1093-
///
1094-
/// If this property is null, then [PopupMenuThemeData.padding] is used.
1095-
/// If [PopupMenuThemeData.padding] is also null, then
1096-
/// EdgeInsets.symmetric(vertical: 8.0) is used.
1097-
final EdgeInsetsGeometry? menuPadding;
1098-
10991081
/// Whether detected gestures should provide acoustic and/or haptic feedback.
11001082
///
11011083
/// For example, on Android a tap will produce a clicking sound and a
@@ -1139,11 +1121,6 @@ class PopupMenuButtonState<T> extends State<PopupMenuButton<T>> {
11391121
),
11401122
Offset.zero & overlay.size,
11411123
);
1142-
1143-
final EdgeInsetsGeometry menuPadding = widget.menuPadding ??
1144-
popupMenuTheme.padding ??
1145-
const EdgeInsets.symmetric(vertical: _kMenuVerticalPadding);
1146-
11471124
final List<PopupMenuEntry<T>> items = widget.itemBuilder(context);
11481125
// Only show the menu if there is something to show
11491126
if (items.isNotEmpty) {
@@ -1152,7 +1129,6 @@ class PopupMenuButtonState<T> extends State<PopupMenuButton<T>> {
11521129
elevation: widget.elevation ?? popupMenuTheme.elevation,
11531130
items: items,
11541131
initialValue: widget.initialValue,
1155-
padding: menuPadding,
11561132
position: position,
11571133
shape: widget.shape ?? popupMenuTheme.shape,
11581134
color: widget.color ?? popupMenuTheme.color,

packages/flutter/lib/src/material/popup_menu_theme.dart

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ class PopupMenuThemeData with Diagnosticable {
4040
this.textStyle,
4141
this.enableFeedback,
4242
this.mouseCursor,
43-
this.padding,
4443
});
4544

4645
/// The background color of the popup menu.
@@ -65,11 +64,6 @@ class PopupMenuThemeData with Diagnosticable {
6564
/// If specified, overrides the default value of [PopupMenuItem.mouseCursor].
6665
final MaterialStateProperty<MouseCursor?>? mouseCursor;
6766

68-
/// If specified, defines the padding for the popup menu of [PopupMenuButton].
69-
///
70-
/// If [PopupMenuButton.menuPadding] is provided, [padding] is ignored.
71-
final EdgeInsetsGeometry? padding;
72-
7367
/// Creates a copy of this object with the given fields replaced with the
7468
/// new values.
7569
PopupMenuThemeData copyWith({
@@ -79,7 +73,6 @@ class PopupMenuThemeData with Diagnosticable {
7973
TextStyle? textStyle,
8074
bool? enableFeedback,
8175
MaterialStateProperty<MouseCursor?>? mouseCursor,
82-
EdgeInsets? padding,
8376
}) {
8477
return PopupMenuThemeData(
8578
color: color ?? this.color,
@@ -88,7 +81,6 @@ class PopupMenuThemeData with Diagnosticable {
8881
textStyle: textStyle ?? this.textStyle,
8982
enableFeedback: enableFeedback ?? this.enableFeedback,
9083
mouseCursor: mouseCursor ?? this.mouseCursor,
91-
padding: padding ?? this.padding,
9284
);
9385
}
9486

@@ -108,7 +100,6 @@ class PopupMenuThemeData with Diagnosticable {
108100
textStyle: TextStyle.lerp(a?.textStyle, b?.textStyle, t),
109101
enableFeedback: t < 0.5 ? a?.enableFeedback : b?.enableFeedback,
110102
mouseCursor: t < 0.5 ? a?.mouseCursor : b?.mouseCursor,
111-
padding: EdgeInsetsGeometry.lerp(a?.padding, b?.padding, t),
112103
);
113104
}
114105

@@ -120,8 +111,7 @@ class PopupMenuThemeData with Diagnosticable {
120111
elevation,
121112
textStyle,
122113
enableFeedback,
123-
mouseCursor,
124-
padding,
114+
mouseCursor
125115
);
126116
}
127117

@@ -137,8 +127,7 @@ class PopupMenuThemeData with Diagnosticable {
137127
&& other.shape == shape
138128
&& other.textStyle == textStyle
139129
&& other.enableFeedback == enableFeedback
140-
&& other.mouseCursor == mouseCursor
141-
&& other.padding == padding;
130+
&& other.mouseCursor == mouseCursor;
142131
}
143132

144133
@override
@@ -150,7 +139,6 @@ class PopupMenuThemeData with Diagnosticable {
150139
properties.add(DiagnosticsProperty<TextStyle>('text style', textStyle, defaultValue: null));
151140
properties.add(DiagnosticsProperty<bool>('enableFeedback', enableFeedback, defaultValue: null));
152141
properties.add(DiagnosticsProperty<MaterialStateProperty<MouseCursor?>>('mouseCursor', mouseCursor, defaultValue: null));
153-
properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('padding', padding, defaultValue: null));
154142
}
155143
}
156144

packages/flutter/test/material/popup_menu_test.dart

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,72 +1471,6 @@ void main() {
14711471
expect(tester.widget<Container>(find.widgetWithText(Container, 'Item 3')).padding, const EdgeInsets.all(20));
14721472
});
14731473

1474-
testWidgets('PopupMenu custom padding', (WidgetTester tester) async {
1475-
final Key popupMenuButtonWithDefaultPaddingKey = UniqueKey();
1476-
final Key popupMenuButtonWithOverriddenPaddingKey = UniqueKey();
1477-
1478-
const EdgeInsets padding = EdgeInsets.zero;
1479-
1480-
await tester.pumpWidget(
1481-
MaterialApp(
1482-
home: Scaffold(
1483-
body: Column(
1484-
children: <PopupMenuButton<String>>[
1485-
PopupMenuButton<String>(
1486-
key: popupMenuButtonWithDefaultPaddingKey,
1487-
child: const Text('button'),
1488-
onSelected: (String result) {},
1489-
itemBuilder: (BuildContext context) {
1490-
return <PopupMenuEntry<String>>[
1491-
const PopupMenuItem<String>(
1492-
value: '0',
1493-
child: Text('Item 0'),
1494-
),
1495-
];
1496-
},
1497-
),
1498-
PopupMenuButton<String>(
1499-
menuPadding: padding,
1500-
key: popupMenuButtonWithOverriddenPaddingKey,
1501-
child: const Text('button'),
1502-
onSelected: (String result) {},
1503-
itemBuilder: (BuildContext context) {
1504-
return <PopupMenuEntry<String>>[
1505-
const PopupMenuItem<String>(
1506-
value: '0',
1507-
child: Text('Item 0'),
1508-
),
1509-
];
1510-
},
1511-
)
1512-
],
1513-
),
1514-
),
1515-
),
1516-
);
1517-
1518-
final Finder popupFinder = find.byType(SingleChildScrollView);
1519-
// Show the menu
1520-
await tester.tap(find.byKey(popupMenuButtonWithDefaultPaddingKey));
1521-
await tester.pumpAndSettle();
1522-
1523-
expect(tester.widget<SingleChildScrollView>(popupFinder).padding,
1524-
const EdgeInsets.symmetric(vertical: 8),
1525-
reason: 'The popup without explicit paddings should utilise the default ones.',);
1526-
1527-
// Close previous menu
1528-
await tester.tap(find.byKey(popupMenuButtonWithDefaultPaddingKey), warnIfMissed: false);
1529-
await tester.pumpAndSettle();
1530-
1531-
// Show the menu
1532-
await tester.tap(find.byKey(popupMenuButtonWithOverriddenPaddingKey));
1533-
await tester.pumpAndSettle();
1534-
1535-
expect(tester.widget<SingleChildScrollView>(popupFinder).padding,
1536-
padding,
1537-
reason: 'The popup should utilise explicitly set paddings.',);
1538-
});
1539-
15401474
testWidgets('CheckedPopupMenuItem child height is a minimum, child is vertically centered', (WidgetTester tester) async {
15411475
final Key popupMenuButtonKey = UniqueKey();
15421476
final Type menuItemType = const CheckedPopupMenuItem<String>(child: Text('item')).runtimeType;

packages/flutter/test/material/popup_menu_theme_test.dart

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ PopupMenuThemeData _popupMenuTheme() {
1313
shape: BeveledRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(12))),
1414
elevation: 12.0,
1515
textStyle: TextStyle(color: Color(0xffffffff), textBaseline: TextBaseline.alphabetic),
16-
padding: EdgeInsets.symmetric(vertical: 6, horizontal: 6),
1716
);
1817
}
1918

@@ -196,7 +195,6 @@ void main() {
196195
);
197196
const double elevation = 7.0;
198197
const TextStyle textStyle = TextStyle(color: Color(0x00000000), textBaseline: TextBaseline.alphabetic);
199-
const EdgeInsets menuPadding = EdgeInsets.zero;
200198

201199
await tester.pumpWidget(MaterialApp(
202200
theme: ThemeData(popupMenuTheme: popupMenuTheme),
@@ -209,7 +207,6 @@ void main() {
209207
elevation: elevation,
210208
color: color,
211209
shape: shape,
212-
menuPadding: menuPadding,
213210
itemBuilder: (BuildContext context) {
214211
return <PopupMenuEntry<void>>[
215212
PopupMenuItem<void>(
@@ -253,12 +250,6 @@ void main() {
253250
).last,
254251
);
255252
expect(text.style, textStyle);
256-
257-
/// PopupMenu widget is private so in order to test padding the widget
258-
/// with the popup padding is extracted.
259-
final SingleChildScrollView popupMenu = tester.widget<SingleChildScrollView>
260-
(find.byType(SingleChildScrollView));
261-
expect(popupMenu.padding, menuPadding);
262253
});
263254

264255
testWidgets('ThemeData.popupMenuTheme properties are utilized', (WidgetTester tester) async {
@@ -267,8 +258,6 @@ void main() {
267258
final Key enabledPopupItemKey = UniqueKey();
268259
final Key disabledPopupItemKey = UniqueKey();
269260

270-
const EdgeInsets themePadding = EdgeInsets.zero;
271-
272261
await tester.pumpWidget(MaterialApp(
273262
key: popupButtonApp,
274263
home: Material(
@@ -286,7 +275,6 @@ void main() {
286275
}
287276
return SystemMouseCursors.alias;
288277
}),
289-
padding: themePadding,
290278
),
291279
child: PopupMenuButton<void>(
292280
key: popupButtonKey,
@@ -345,11 +333,5 @@ void main() {
345333
await gesture.down(tester.getCenter(find.byKey(enabledPopupItemKey)));
346334
await tester.pumpAndSettle();
347335
expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.alias);
348-
349-
/// PopupMenu widget is private so in order to test padding we extract
350-
/// the widget which holds the padding.
351-
final SingleChildScrollView popupMenu = tester.widget<SingleChildScrollView>
352-
(find.byType(SingleChildScrollView));
353-
expect(popupMenu.padding, themePadding);
354336
});
355337
}

0 commit comments

Comments
 (0)