Unverified Commit 790ca116 authored by Aliaksei Chorny's avatar Aliaksei Chorny Committed by GitHub

Add splashRadius to PopupMenuButton (#91148)

parent 10658266
...@@ -985,6 +985,7 @@ class PopupMenuButton<T> extends StatefulWidget { ...@@ -985,6 +985,7 @@ class PopupMenuButton<T> extends StatefulWidget {
this.elevation, this.elevation,
this.padding = const EdgeInsets.all(8.0), this.padding = const EdgeInsets.all(8.0),
this.child, this.child,
this.splashRadius,
this.icon, this.icon,
this.iconSize, this.iconSize,
this.offset = Offset.zero, this.offset = Offset.zero,
...@@ -1035,6 +1036,11 @@ class PopupMenuButton<T> extends StatefulWidget { ...@@ -1035,6 +1036,11 @@ class PopupMenuButton<T> extends StatefulWidget {
/// to set the padding to zero. /// to set the padding to zero.
final EdgeInsetsGeometry padding; 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 /// If provided, [child] is the widget used for this button
/// and the button will utilize an [InkWell] for taps. /// and the button will utilize an [InkWell] for taps.
final Widget? child; final Widget? child;
...@@ -1169,6 +1175,7 @@ class PopupMenuButtonState<T> extends State<PopupMenuButton<T>> { ...@@ -1169,6 +1175,7 @@ class PopupMenuButtonState<T> extends State<PopupMenuButton<T>> {
child: InkWell( child: InkWell(
onTap: widget.enabled ? showButtonMenu : null, onTap: widget.enabled ? showButtonMenu : null,
canRequestFocus: _canRequestFocus, canRequestFocus: _canRequestFocus,
radius: widget.splashRadius,
enableFeedback: enableFeedback, enableFeedback: enableFeedback,
child: widget.child, child: widget.child,
), ),
...@@ -1177,6 +1184,7 @@ class PopupMenuButtonState<T> extends State<PopupMenuButton<T>> { ...@@ -1177,6 +1184,7 @@ class PopupMenuButtonState<T> extends State<PopupMenuButton<T>> {
return IconButton( return IconButton(
icon: widget.icon ?? Icon(Icons.adaptive.more), icon: widget.icon ?? Icon(Icons.adaptive.more),
padding: widget.padding, padding: widget.padding,
splashRadius: widget.splashRadius,
iconSize: widget.iconSize ?? 24.0, iconSize: widget.iconSize ?? 24.0,
tooltip: widget.tooltip ?? MaterialLocalizations.of(context).showMenuTooltip, tooltip: widget.tooltip ?? MaterialLocalizations.of(context).showMenuTooltip,
onPressed: widget.enabled ? showButtonMenu : null, onPressed: widget.enabled ? showButtonMenu : null,
......
...@@ -2479,6 +2479,63 @@ void main() { ...@@ -2479,6 +2479,63 @@ void main() {
// The 8.0 pixels is [_kMenuScreenPadding]. // The 8.0 pixels is [_kMenuScreenPadding].
expect(popupMenu, const Offset(8.0, 50.0)); expect(popupMenu, const Offset(8.0, 50.0));
}); });
testWidgets('PopupMenuButton custom splash radius', (WidgetTester tester) async {
Future<void> buildFrameWithoutChild({double? splashRadius}) {
return tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Center(
child: PopupMenuButton<String>(
splashRadius: splashRadius,
itemBuilder: (_) => <PopupMenuEntry<String>>[
const PopupMenuItem<String>(
value: 'value',
child: Text('child'),
),
],
),
),
),
),
);
}
Future<void> buildFrameWithChild({double? splashRadius}) {
return tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Center(
child: PopupMenuButton<String>(
splashRadius: splashRadius,
child: const Text('An item'),
itemBuilder: (_) => <PopupMenuEntry<String>>[
const PopupMenuDivider()
],
),
),
),
),
);
}
await buildFrameWithoutChild();
expect(tester.widget<InkResponse>(find.byType(InkResponse)).radius,
Material.defaultSplashRadius);
await buildFrameWithChild();
expect(tester.widget<InkWell>(find.byType(InkWell)).radius, null);
const double testSplashRadius = 50;
await buildFrameWithoutChild(splashRadius: testSplashRadius);
expect(tester.widget<InkResponse>(find.byType(InkResponse)).radius,
testSplashRadius);
await buildFrameWithChild(splashRadius: testSplashRadius);
expect(tester.widget<InkWell>(find.byType(InkWell)).radius,
testSplashRadius);
});
} }
class TestApp extends StatefulWidget { class TestApp extends StatefulWidget {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment