From 311c0064d8b5114d3933585198b6b273c2e7dd14 Mon Sep 17 00:00:00 2001 From: Tirth Date: Wed, 6 Mar 2024 01:12:30 +0530 Subject: [PATCH] Adds missing `style` to `PopupMenuButton` (#143392) Adds missing `style` to `PopupMenuButton`. Fixes: #114709 --- .../flutter/lib/src/material/popup_menu.dart | 12 +++++++++ .../test/material/popup_menu_test.dart | 27 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/packages/flutter/lib/src/material/popup_menu.dart b/packages/flutter/lib/src/material/popup_menu.dart index 8746b3465bf..5083add60bd 100644 --- a/packages/flutter/lib/src/material/popup_menu.dart +++ b/packages/flutter/lib/src/material/popup_menu.dart @@ -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 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 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 createState() => PopupMenuButtonState(); } @@ -1455,6 +1466,7 @@ class PopupMenuButtonState extends State> { tooltip: widget.tooltip ?? MaterialLocalizations.of(context).showMenuTooltip, onPressed: widget.enabled ? showButtonMenu : null, enableFeedback: enableFeedback, + style: widget.style, ); } } diff --git a/packages/flutter/test/material/popup_menu_test.dart b/packages/flutter/test/material/popup_menu_test.dart index 7a07d1e2b23..cfce4bc128a 100644 --- a/packages/flutter/test/material/popup_menu_test.dart +++ b/packages/flutter/test/material/popup_menu_test.dart @@ -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( + style: const ButtonStyle( + iconColor: MaterialStatePropertyAll(Colors.red), + ), + itemBuilder: (BuildContext context) { + return >[ + const PopupMenuItem( + value: 1, + child: Text('One'), + ), + ]; + }, + ), + ), + ), + ); + final RichText iconText = tester.firstWidget(find.descendant( + of: find.byType(PopupMenuButton), + matching: find.byType(RichText), + )); + expect(iconText.text.style?.color, Colors.red); + }); } Matcher overlaps(Rect other) => OverlapsMatcher(other);