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
This commit is contained in:
John Stef
2024-07-16 23:27:11 +03:00
committed by GitHub
parent e1cd7b11f6
commit aed548992a
2 changed files with 50 additions and 0 deletions

View File

@@ -1196,6 +1196,7 @@ class PopupMenuButton<T> 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<T> 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<T> extends State<PopupMenuButton<T>> {
return Tooltip(
message: widget.tooltip ?? MaterialLocalizations.of(context).showMenuTooltip,
child: InkWell(
borderRadius: widget.borderRadius,
onTap: widget.enabled ? showButtonMenu : null,
canRequestFocus: _canRequestFocus,
radius: widget.splashRadius,

View File

@@ -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<String>(
borderRadius: borderRadius,
itemBuilder: (_) => <PopupMenuEntry<String>>[
const PopupMenuItem<String>(
value: 'value',
child: Text('Item 0'),
),
],
child: const Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
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<InkWell>(find.byType(InkWell));
expect(inkWell.borderRadius, isNull);
// Popup menu with fixed borderRadius.
await tester.pumpWidget(buildPopupMenu(borderRadius: borderRadius));
await tester.pumpAndSettle();
inkWell = tester.widget<InkWell>(find.byType(InkWell));
expect(inkWell.borderRadius, borderRadius);
});
}
Matcher overlaps(Rect other) => OverlapsMatcher(other);