diff --git a/packages/flutter/lib/src/material/popup_menu.dart b/packages/flutter/lib/src/material/popup_menu.dart index a019c96e60..3ca45c8aeb 100644 --- a/packages/flutter/lib/src/material/popup_menu.dart +++ b/packages/flutter/lib/src/material/popup_menu.dart @@ -985,6 +985,7 @@ class PopupMenuButton extends StatefulWidget { this.elevation, this.padding = const EdgeInsets.all(8.0), this.child, + this.splashRadius, this.icon, this.iconSize, this.offset = Offset.zero, @@ -1035,6 +1036,11 @@ class PopupMenuButton extends StatefulWidget { /// to set the padding to zero. final EdgeInsetsGeometry padding; + /// The splash radius. + /// + /// If null, default splash radius of [InkWell] or [IconButton] is used. + final double? splashRadius; + /// If provided, [child] is the widget used for this button /// and the button will utilize an [InkWell] for taps. final Widget? child; @@ -1169,6 +1175,7 @@ class PopupMenuButtonState extends State> { child: InkWell( onTap: widget.enabled ? showButtonMenu : null, canRequestFocus: _canRequestFocus, + radius: widget.splashRadius, enableFeedback: enableFeedback, child: widget.child, ), @@ -1177,6 +1184,7 @@ class PopupMenuButtonState extends State> { return IconButton( icon: widget.icon ?? Icon(Icons.adaptive.more), padding: widget.padding, + splashRadius: widget.splashRadius, iconSize: widget.iconSize ?? 24.0, tooltip: widget.tooltip ?? MaterialLocalizations.of(context).showMenuTooltip, onPressed: widget.enabled ? showButtonMenu : null, diff --git a/packages/flutter/test/material/popup_menu_test.dart b/packages/flutter/test/material/popup_menu_test.dart index 6d6328fe23..e9fb4b9ecd 100644 --- a/packages/flutter/test/material/popup_menu_test.dart +++ b/packages/flutter/test/material/popup_menu_test.dart @@ -2479,6 +2479,63 @@ void main() { // The 8.0 pixels is [_kMenuScreenPadding]. expect(popupMenu, const Offset(8.0, 50.0)); }); + + testWidgets('PopupMenuButton custom splash radius', (WidgetTester tester) async { + Future buildFrameWithoutChild({double? splashRadius}) { + return tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: Center( + child: PopupMenuButton( + splashRadius: splashRadius, + itemBuilder: (_) => >[ + const PopupMenuItem( + value: 'value', + child: Text('child'), + ), + ], + ), + ), + ), + ), + ); + } + + Future buildFrameWithChild({double? splashRadius}) { + return tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: Center( + child: PopupMenuButton( + splashRadius: splashRadius, + child: const Text('An item'), + itemBuilder: (_) => >[ + const PopupMenuDivider() + ], + ), + ), + ), + ), + ); + } + + + await buildFrameWithoutChild(); + expect(tester.widget(find.byType(InkResponse)).radius, + Material.defaultSplashRadius); + await buildFrameWithChild(); + expect(tester.widget(find.byType(InkWell)).radius, null); + + + const double testSplashRadius = 50; + + await buildFrameWithoutChild(splashRadius: testSplashRadius); + expect(tester.widget(find.byType(InkResponse)).radius, + testSplashRadius); + await buildFrameWithChild(splashRadius: testSplashRadius); + expect(tester.widget(find.byType(InkWell)).radius, + testSplashRadius); + }); } class TestApp extends StatefulWidget {