forked from firka/flutter
Add splashRadius to PopupMenuButton (#91148)
This commit is contained in:
@@ -985,6 +985,7 @@ class PopupMenuButton<T> 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<T> 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<T> extends State<PopupMenuButton<T>> {
|
||||
child: InkWell(
|
||||
onTap: widget.enabled ? showButtonMenu : null,
|
||||
canRequestFocus: _canRequestFocus,
|
||||
radius: widget.splashRadius,
|
||||
enableFeedback: enableFeedback,
|
||||
child: widget.child,
|
||||
),
|
||||
@@ -1177,6 +1184,7 @@ class PopupMenuButtonState<T> extends State<PopupMenuButton<T>> {
|
||||
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,
|
||||
|
||||
@@ -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<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 {
|
||||
|
||||
Reference in New Issue
Block a user