Adds missing style to PopupMenuButton (#143392)

Adds missing `style` to `PopupMenuButton`.

Fixes: #114709
This commit is contained in:
Tirth 2024-03-06 01:12:30 +05:30 committed by GitHub
parent bb8fc6e9a9
commit 311c0064d8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 39 additions and 0 deletions

View file

@ -7,6 +7,7 @@ import 'package:flutter/rendering.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter/widgets.dart';
import 'button_style.dart';
import 'color_scheme.dart';
import 'colors.dart';
import 'constants.dart';
@ -1149,6 +1150,7 @@ class PopupMenuButton<T> extends StatefulWidget {
this.clipBehavior = Clip.none,
this.useRootNavigator = false,
this.popUpAnimationStyle,
this.style,
}) : assert(
!(child != null && icon != null),
'You can only pass [child] or [icon], not both.',
@ -1343,6 +1345,15 @@ class PopupMenuButton<T> extends StatefulWidget {
/// If this is null, then the default animation will be used.
final AnimationStyle? popUpAnimationStyle;
/// Customizes this icon button's appearance.
///
/// The [style] is only used for Material 3 [IconButton]s. If [ThemeData.useMaterial3]
/// is set to true, [style] is preferred for icon button customization, and any
/// parameters defined in [style] will override the same parameters in [IconButton].
///
/// Null by default.
final ButtonStyle? style;
@override
PopupMenuButtonState<T> createState() => PopupMenuButtonState<T>();
}
@ -1455,6 +1466,7 @@ class PopupMenuButtonState<T> extends State<PopupMenuButton<T>> {
tooltip: widget.tooltip ?? MaterialLocalizations.of(context).showMenuTooltip,
onPressed: widget.enabled ? showButtonMenu : null,
enableFeedback: enableFeedback,
style: widget.style,
);
}
}

View file

@ -4060,6 +4060,33 @@ void main() {
expect(listViewportBounds.bottomRight.dy, lessThanOrEqualTo(windowSize.height));
expect(listViewportBounds, overlaps(buttonBounds));
});
testWidgets('PopupMenuButton honors style', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: PopupMenuButton<int>(
style: const ButtonStyle(
iconColor: MaterialStatePropertyAll<Color>(Colors.red),
),
itemBuilder: (BuildContext context) {
return <PopupMenuItem<int>>[
const PopupMenuItem<int>(
value: 1,
child: Text('One'),
),
];
},
),
),
),
);
final RichText iconText = tester.firstWidget(find.descendant(
of: find.byType(PopupMenuButton<int>),
matching: find.byType(RichText),
));
expect(iconText.text.style?.color, Colors.red);
});
}
Matcher overlaps(Rect other) => OverlapsMatcher(other);