Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions packages/material_ui/lib/src/menu_anchor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3327,24 +3327,22 @@ class _MenuItemLabel extends StatelessWidget {
Widget leadings;
if (overflowAxis == Axis.vertical) {
leadings = Expanded(
child: ClipRect(
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
?leadingIcon,
if (child != null)
Expanded(
child: ClipRect(
child: Padding(
padding: leadingIcon != null
? EdgeInsetsDirectional.only(start: horizontalPadding)
: EdgeInsets.zero,
child: child,
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
?leadingIcon,
if (child != null)
Expanded(
child: ClipRect(
child: Padding(
padding: leadingIcon != null
? EdgeInsetsDirectional.only(start: horizontalPadding)
: EdgeInsets.zero,
child: child,
),
),
],
),
),
],
),
);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
changelog: |
- Fixes decorations on `MenuItemButton.leadingIcon`, such as `Badge`, being clipped to the icon's bounds in vertically expanding menus.
version: patch
44 changes: 44 additions & 0 deletions packages/material_ui/test/menu_anchor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3337,6 +3337,50 @@ void main() {
expect(exception, isAssertionError);
});

// This is a regression test for https://github.com/flutter/flutter/issues/192732.
testWidgets('MenuItemButton does not clip leadingIcon', (WidgetTester tester) async {
const label = 'This is a very long menu item label that must be clipped';
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: MenuAnchor(
menuChildren: <Widget>[
SizedBox(
width: 200.0,
child: MenuItemButton(
leadingIcon: const Badge(
label: Text('1'),
child: Icon(Icons.add, key: Key('leading')),
),
onPressed: () {},
child: const Text(label, maxLines: 1),
),
),
],
builder: (BuildContext context, MenuController controller, Widget? child) {
return TextButton(onPressed: controller.open, child: const Text('Open'));
},
),
),
),
);

await tester.tap(find.text('Open'));
await tester.pumpAndSettle();

// Decorations that paint outside the leading icon's bounds stay visible.
expect(
find.ancestor(of: find.byKey(const Key('leading')), matching: find.byType(ClipRect)),
findsNothing,
);

// The label itself is still clipped so that long labels truncate.
final Finder labelFinder = find.text(label);
expect(find.ancestor(of: labelFinder, matching: find.byType(ClipRect)), findsOneWidget);
final RenderParagraph paragraph = tester.renderObject<RenderParagraph>(labelFinder);
expect(paragraph.didExceedMaxLines, isTrue);
});

testWidgets('MenuItemButton.styleFrom overlayColor overrides default overlay color', (
WidgetTester tester,
) async {
Expand Down
Loading