Skip to content

Commit 5f71179

Browse files
authored
Wire up MenuAnchor clipBehaviour property (#123632)
Wire up MenuAnchor clipBehaviour property
1 parent 8c5d223 commit 5f71179

File tree

2 files changed

+67
-6
lines changed

2 files changed

+67
-6
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class MenuAnchor extends StatefulWidget {
127127
this.childFocusNode,
128128
this.style,
129129
this.alignmentOffset = Offset.zero,
130-
this.clipBehavior = Clip.none,
130+
this.clipBehavior = Clip.hardEdge,
131131
this.anchorTapClosesMenu = false,
132132
this.onOpen,
133133
this.onClose,
@@ -183,7 +183,7 @@ class MenuAnchor extends StatefulWidget {
183183

184184
/// {@macro flutter.material.Material.clipBehavior}
185185
///
186-
/// Defaults to [Clip.none].
186+
/// Defaults to [Clip.hardEdge].
187187
final Clip clipBehavior;
188188

189189
/// Whether the menus will be closed if the anchor area is tapped.
@@ -1530,7 +1530,7 @@ class SubmenuButton extends StatefulWidget {
15301530
this.style,
15311531
this.menuStyle,
15321532
this.alignmentOffset,
1533-
this.clipBehavior = Clip.none,
1533+
this.clipBehavior = Clip.hardEdge,
15341534
this.focusNode,
15351535
this.statesController,
15361536
this.leadingIcon,
@@ -1584,7 +1584,7 @@ class SubmenuButton extends StatefulWidget {
15841584

15851585
/// {@macro flutter.material.Material.clipBehavior}
15861586
///
1587-
/// Defaults to [Clip.none].
1587+
/// Defaults to [Clip.hardEdge].
15881588
final Clip clipBehavior;
15891589

15901590
/// {@macro flutter.widgets.Focus.focusNode}
@@ -3312,7 +3312,7 @@ class _MenuPanelState extends State<_MenuPanel> {
33123312
shadowColor: shadowColor,
33133313
surfaceTintColor: surfaceTintColor,
33143314
type: backgroundColor == null ? MaterialType.transparency : MaterialType.canvas,
3315-
clipBehavior: Clip.hardEdge,
3315+
clipBehavior: widget.clipBehavior,
33163316
child: Padding(
33173317
padding: resolvedPadding,
33183318
child: SingleChildScrollView(

packages/flutter/test/material/menu_anchor_test.dart

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,67 @@ void main() {
945945
expect(material.color, equals(Colors.red));
946946
});
947947

948+
testWidgets('MenuAnchor clip behavior', (WidgetTester tester) async {
949+
await tester.pumpWidget(
950+
MaterialApp(
951+
home: Material(
952+
child: Center(
953+
child: MenuAnchor(
954+
menuChildren: const <Widget> [
955+
MenuItemButton(
956+
child: Text('Button 1'),
957+
),
958+
],
959+
builder: (BuildContext context, MenuController controller, Widget? child) {
960+
return FilledButton(
961+
onPressed: () {
962+
controller.open();
963+
},
964+
child: const Text('Tap me'),
965+
);
966+
},
967+
),
968+
)
969+
)
970+
)
971+
);
972+
await tester.tap(find.text('Tap me'));
973+
await tester.pump();
974+
// Test default clip behavior.
975+
expect(getMenuBarMaterial(tester).clipBehavior, equals(Clip.hardEdge));
976+
// Close the menu.
977+
await tester.tapAt(const Offset(10.0, 10.0));
978+
await tester.pumpAndSettle();
979+
await tester.pumpWidget(
980+
MaterialApp(
981+
home: Material(
982+
child: Center(
983+
child: MenuAnchor(
984+
clipBehavior: Clip.antiAlias,
985+
menuChildren: const <Widget> [
986+
MenuItemButton(
987+
child: Text('Button 1'),
988+
),
989+
],
990+
builder: (BuildContext context, MenuController controller, Widget? child) {
991+
return FilledButton(
992+
onPressed: () {
993+
controller.open();
994+
},
995+
child: const Text('Tap me'),
996+
);
997+
},
998+
),
999+
)
1000+
)
1001+
)
1002+
);
1003+
await tester.tap(find.text('Tap me'));
1004+
await tester.pump();
1005+
// Test custom clip behavior.
1006+
expect(getMenuBarMaterial(tester).clipBehavior, equals(Clip.antiAlias));
1007+
});
1008+
9481009
testWidgets('open and close works', (WidgetTester tester) async {
9491010
await tester.pumpWidget(
9501011
MaterialApp(
@@ -2057,7 +2118,7 @@ void main() {
20572118
'focusNode: null',
20582119
'menuStyle: MenuStyle#00000(backgroundColor: MaterialStatePropertyAll(MaterialColor(primary value: Color(0xff4caf50))), elevation: MaterialStatePropertyAll(20.0), shape: MaterialStatePropertyAll(RoundedRectangleBorder(BorderSide(width: 0.0, style: none), BorderRadius.zero)))',
20592120
'alignmentOffset: null',
2060-
'clipBehavior: none',
2121+
'clipBehavior: hardEdge',
20612122
],
20622123
),
20632124
);

0 commit comments

Comments
 (0)