Skip to content

Commit 3c0e57e

Browse files
johnstef99TytaniumDev
authored andcommitted
Add borderRadius property to PopupMenuButton (flutter#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: flutter#151227 https://github.com/flutter/flutter/assets/20647774/93feb0a4-c4ff-4059-bde2-e59c4d35e2b6
1 parent 3ec5b3a commit 3c0e57e

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

packages/flutter/lib/src/material/popup_menu.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,7 @@ class PopupMenuButton<T> extends StatefulWidget {
11961196
this.padding = const EdgeInsets.all(8.0),
11971197
this.menuPadding,
11981198
this.child,
1199+
this.borderRadius,
11991200
this.splashRadius,
12001201
this.icon,
12011202
this.iconSize,
@@ -1292,6 +1293,11 @@ class PopupMenuButton<T> extends StatefulWidget {
12921293
/// and the button will utilize an [InkWell] for taps.
12931294
final Widget? child;
12941295

1296+
/// The border radius for the [InkWell] that wraps the [child].
1297+
///
1298+
/// Defaults to null, which indicates no border radius should be applied.
1299+
final BorderRadius? borderRadius;
1300+
12951301
/// If provided, the [icon] is used for this button
12961302
/// and the button will behave like an [IconButton].
12971303
final Widget? icon;
@@ -1527,6 +1533,7 @@ class PopupMenuButtonState<T> extends State<PopupMenuButton<T>> {
15271533
return Tooltip(
15281534
message: widget.tooltip ?? MaterialLocalizations.of(context).showMenuTooltip,
15291535
child: InkWell(
1536+
borderRadius: widget.borderRadius,
15301537
onTap: widget.enabled ? showButtonMenu : null,
15311538
canRequestFocus: _canRequestFocus,
15321539
radius: widget.splashRadius,

packages/flutter/test/material/popup_menu_test.dart

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4242,6 +4242,49 @@ void main() {
42424242
));
42434243
expect(iconText.text.style?.color, Colors.red);
42444244
});
4245+
4246+
testWidgets("Popup menu child's InkWell borderRadius", (WidgetTester tester) async {
4247+
final BorderRadius borderRadius = BorderRadius.circular(20);
4248+
4249+
Widget buildPopupMenu({required BorderRadius? borderRadius}) {
4250+
return MaterialApp(
4251+
home: Scaffold(
4252+
body: Center(
4253+
child: PopupMenuButton<String>(
4254+
borderRadius: borderRadius,
4255+
itemBuilder: (_) => <PopupMenuEntry<String>>[
4256+
const PopupMenuItem<String>(
4257+
value: 'value',
4258+
child: Text('Item 0'),
4259+
),
4260+
],
4261+
child: const Row(
4262+
mainAxisSize: MainAxisSize.min,
4263+
children: <Widget>[
4264+
Text('Pop up menu'),
4265+
Icon(Icons.arrow_drop_down),
4266+
],
4267+
),
4268+
),
4269+
),
4270+
),
4271+
);
4272+
}
4273+
4274+
// Popup menu with default null borderRadius.
4275+
await tester.pumpWidget(buildPopupMenu(borderRadius: null));
4276+
await tester.pumpAndSettle();
4277+
4278+
InkWell inkWell = tester.widget<InkWell>(find.byType(InkWell));
4279+
expect(inkWell.borderRadius, isNull);
4280+
4281+
// Popup menu with fixed borderRadius.
4282+
await tester.pumpWidget(buildPopupMenu(borderRadius: borderRadius));
4283+
await tester.pumpAndSettle();
4284+
4285+
inkWell = tester.widget<InkWell>(find.byType(InkWell));
4286+
expect(inkWell.borderRadius, borderRadius);
4287+
});
42454288
}
42464289

42474290
Matcher overlaps(Rect other) => OverlapsMatcher(other);

0 commit comments

Comments
 (0)