From aed548992a0e8e8eb4d1d5ec5a8ef5af7c89aff2 Mon Sep 17 00:00:00 2001 From: John Stef Date: Tue, 16 Jul 2024 23:27:11 +0300 Subject: [PATCH] Add borderRadius property to PopupMenuButton (#151228) This PR is adding borderRadius property to PopupMenuButton. PopupMenuButton has a child wrapped in an InkWell widget where as of right now you can't customize it's border radius resulting in wrong splash effect when the child has border radius. Fixes: #151227 https://github.com/flutter/flutter/assets/20647774/93feb0a4-c4ff-4059-bde2-e59c4d35e2b6 --- .../flutter/lib/src/material/popup_menu.dart | 7 +++ .../test/material/popup_menu_test.dart | 43 +++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/packages/flutter/lib/src/material/popup_menu.dart b/packages/flutter/lib/src/material/popup_menu.dart index 6f49ad2d7f..8daee996f1 100644 --- a/packages/flutter/lib/src/material/popup_menu.dart +++ b/packages/flutter/lib/src/material/popup_menu.dart @@ -1196,6 +1196,7 @@ class PopupMenuButton extends StatefulWidget { this.padding = const EdgeInsets.all(8.0), this.menuPadding, this.child, + this.borderRadius, this.splashRadius, this.icon, this.iconSize, @@ -1292,6 +1293,11 @@ class PopupMenuButton extends StatefulWidget { /// and the button will utilize an [InkWell] for taps. final Widget? child; + /// The border radius for the [InkWell] that wraps the [child]. + /// + /// Defaults to null, which indicates no border radius should be applied. + final BorderRadius? borderRadius; + /// If provided, the [icon] is used for this button /// and the button will behave like an [IconButton]. final Widget? icon; @@ -1527,6 +1533,7 @@ class PopupMenuButtonState extends State> { return Tooltip( message: widget.tooltip ?? MaterialLocalizations.of(context).showMenuTooltip, child: InkWell( + borderRadius: widget.borderRadius, onTap: widget.enabled ? showButtonMenu : null, canRequestFocus: _canRequestFocus, radius: widget.splashRadius, diff --git a/packages/flutter/test/material/popup_menu_test.dart b/packages/flutter/test/material/popup_menu_test.dart index d6258b98c0..4758f6e7e3 100644 --- a/packages/flutter/test/material/popup_menu_test.dart +++ b/packages/flutter/test/material/popup_menu_test.dart @@ -4242,6 +4242,49 @@ void main() { )); expect(iconText.text.style?.color, Colors.red); }); + + testWidgets("Popup menu child's InkWell borderRadius", (WidgetTester tester) async { + final BorderRadius borderRadius = BorderRadius.circular(20); + + Widget buildPopupMenu({required BorderRadius? borderRadius}) { + return MaterialApp( + home: Scaffold( + body: Center( + child: PopupMenuButton( + borderRadius: borderRadius, + itemBuilder: (_) => >[ + const PopupMenuItem( + value: 'value', + child: Text('Item 0'), + ), + ], + child: const Row( + mainAxisSize: MainAxisSize.min, + children: [ + Text('Pop up menu'), + Icon(Icons.arrow_drop_down), + ], + ), + ), + ), + ), + ); + } + + // Popup menu with default null borderRadius. + await tester.pumpWidget(buildPopupMenu(borderRadius: null)); + await tester.pumpAndSettle(); + + InkWell inkWell = tester.widget(find.byType(InkWell)); + expect(inkWell.borderRadius, isNull); + + // Popup menu with fixed borderRadius. + await tester.pumpWidget(buildPopupMenu(borderRadius: borderRadius)); + await tester.pumpAndSettle(); + + inkWell = tester.widget(find.byType(InkWell)); + expect(inkWell.borderRadius, borderRadius); + }); } Matcher overlaps(Rect other) => OverlapsMatcher(other);