Fix PopupMenuButton
's IconButton
not inheriting IconTheme
size (#100199)
This commit is contained in:
parent
6d0eeb874e
commit
795fe375bc
@ -37,6 +37,7 @@ const double _kMenuMinWidth = 2.0 * _kMenuWidthStep;
|
||||
const double _kMenuVerticalPadding = 8.0;
|
||||
const double _kMenuWidthStep = 56.0;
|
||||
const double _kMenuScreenPadding = 8.0;
|
||||
const double _kDefaultIconSize = 24.0;
|
||||
|
||||
/// Used to configure how the [PopupMenuButton] positions its popup menu.
|
||||
enum PopupMenuPosition {
|
||||
@ -1088,7 +1089,9 @@ class PopupMenuButton<T> extends StatefulWidget {
|
||||
|
||||
/// If provided, the size of the [Icon].
|
||||
///
|
||||
/// If this property is null, the default size is 24.0 pixels.
|
||||
/// If this property is null, then [IconThemeData.size] is used.
|
||||
/// If [IconThemeData.size] is also null, then
|
||||
/// default size is 24.0 pixels.
|
||||
final double? iconSize;
|
||||
|
||||
/// Optional size constraints for the menu.
|
||||
@ -1190,6 +1193,7 @@ class PopupMenuButtonState<T> extends State<PopupMenuButton<T>> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final IconThemeData iconTheme = IconTheme.of(context);
|
||||
final bool enableFeedback = widget.enableFeedback
|
||||
?? PopupMenuTheme.of(context).enableFeedback
|
||||
?? true;
|
||||
@ -1212,7 +1216,7 @@ class PopupMenuButtonState<T> extends State<PopupMenuButton<T>> {
|
||||
icon: widget.icon ?? Icon(Icons.adaptive.more),
|
||||
padding: widget.padding,
|
||||
splashRadius: widget.splashRadius,
|
||||
iconSize: widget.iconSize ?? 24.0,
|
||||
iconSize: widget.iconSize ?? iconTheme.size ?? _kDefaultIconSize,
|
||||
tooltip: widget.tooltip ?? MaterialLocalizations.of(context).showMenuTooltip,
|
||||
onPressed: widget.enabled ? showButtonMenu : null,
|
||||
enableFeedback: enableFeedback,
|
||||
|
@ -2698,6 +2698,51 @@ void main() {
|
||||
|
||||
expect(tester.getTopLeft(find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_PopupMenu<int?>')), const Offset(8.0, 90.0));
|
||||
});
|
||||
|
||||
testWidgets("PopupMenuButton icon inherits IconTheme's size", (WidgetTester tester) async {
|
||||
Widget _buildPopupMenu({double? themeIconSize, double? iconSize}) {
|
||||
return MaterialApp(
|
||||
theme: ThemeData(
|
||||
iconTheme: IconThemeData(
|
||||
size: themeIconSize,
|
||||
),
|
||||
),
|
||||
home: Scaffold(
|
||||
body: Center(
|
||||
child: PopupMenuButton<String>(
|
||||
iconSize: iconSize,
|
||||
itemBuilder: (_) => <PopupMenuEntry<String>>[
|
||||
const PopupMenuItem<String>(
|
||||
value: 'value',
|
||||
child: Text('Item 0'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Popup menu with default icon size.
|
||||
await tester.pumpWidget(_buildPopupMenu());
|
||||
IconButton iconButton = tester.widget(find.widgetWithIcon(IconButton, Icons.more_vert));
|
||||
// Default PopupMenuButton icon size is 24.0.
|
||||
expect(iconButton.iconSize, 24.0);
|
||||
|
||||
// Popup menu with custom theme icon size.
|
||||
await tester.pumpWidget(_buildPopupMenu(themeIconSize: 30.0));
|
||||
await tester.pumpAndSettle();
|
||||
iconButton = tester.widget(find.widgetWithIcon(IconButton, Icons.more_vert));
|
||||
// PopupMenuButton icon inherits IconTheme's size.
|
||||
expect(iconButton.iconSize, 30.0);
|
||||
|
||||
// Popup menu with custom icon size.
|
||||
await tester.pumpWidget(_buildPopupMenu(themeIconSize: 30.0, iconSize: 50.0));
|
||||
await tester.pumpAndSettle();
|
||||
iconButton = tester.widget(find.widgetWithIcon(IconButton, Icons.more_vert));
|
||||
// PopupMenuButton icon size overrides IconTheme's size.
|
||||
expect(iconButton.iconSize, 50.0);
|
||||
});
|
||||
}
|
||||
|
||||
class TestApp extends StatefulWidget {
|
||||
|
Loading…
x
Reference in New Issue
Block a user