Unverified Commit 5f711794 authored by Henry Riehl's avatar Henry Riehl Committed by GitHub

Wire up MenuAnchor clipBehaviour property (#123632)

Wire up MenuAnchor clipBehaviour property
parent 8c5d223b
...@@ -127,7 +127,7 @@ class MenuAnchor extends StatefulWidget { ...@@ -127,7 +127,7 @@ class MenuAnchor extends StatefulWidget {
this.childFocusNode, this.childFocusNode,
this.style, this.style,
this.alignmentOffset = Offset.zero, this.alignmentOffset = Offset.zero,
this.clipBehavior = Clip.none, this.clipBehavior = Clip.hardEdge,
this.anchorTapClosesMenu = false, this.anchorTapClosesMenu = false,
this.onOpen, this.onOpen,
this.onClose, this.onClose,
...@@ -183,7 +183,7 @@ class MenuAnchor extends StatefulWidget { ...@@ -183,7 +183,7 @@ class MenuAnchor extends StatefulWidget {
/// {@macro flutter.material.Material.clipBehavior} /// {@macro flutter.material.Material.clipBehavior}
/// ///
/// Defaults to [Clip.none]. /// Defaults to [Clip.hardEdge].
final Clip clipBehavior; final Clip clipBehavior;
/// Whether the menus will be closed if the anchor area is tapped. /// Whether the menus will be closed if the anchor area is tapped.
...@@ -1530,7 +1530,7 @@ class SubmenuButton extends StatefulWidget { ...@@ -1530,7 +1530,7 @@ class SubmenuButton extends StatefulWidget {
this.style, this.style,
this.menuStyle, this.menuStyle,
this.alignmentOffset, this.alignmentOffset,
this.clipBehavior = Clip.none, this.clipBehavior = Clip.hardEdge,
this.focusNode, this.focusNode,
this.statesController, this.statesController,
this.leadingIcon, this.leadingIcon,
...@@ -1584,7 +1584,7 @@ class SubmenuButton extends StatefulWidget { ...@@ -1584,7 +1584,7 @@ class SubmenuButton extends StatefulWidget {
/// {@macro flutter.material.Material.clipBehavior} /// {@macro flutter.material.Material.clipBehavior}
/// ///
/// Defaults to [Clip.none]. /// Defaults to [Clip.hardEdge].
final Clip clipBehavior; final Clip clipBehavior;
/// {@macro flutter.widgets.Focus.focusNode} /// {@macro flutter.widgets.Focus.focusNode}
...@@ -3312,7 +3312,7 @@ class _MenuPanelState extends State<_MenuPanel> { ...@@ -3312,7 +3312,7 @@ class _MenuPanelState extends State<_MenuPanel> {
shadowColor: shadowColor, shadowColor: shadowColor,
surfaceTintColor: surfaceTintColor, surfaceTintColor: surfaceTintColor,
type: backgroundColor == null ? MaterialType.transparency : MaterialType.canvas, type: backgroundColor == null ? MaterialType.transparency : MaterialType.canvas,
clipBehavior: Clip.hardEdge, clipBehavior: widget.clipBehavior,
child: Padding( child: Padding(
padding: resolvedPadding, padding: resolvedPadding,
child: SingleChildScrollView( child: SingleChildScrollView(
......
...@@ -945,6 +945,67 @@ void main() { ...@@ -945,6 +945,67 @@ void main() {
expect(material.color, equals(Colors.red)); expect(material.color, equals(Colors.red));
}); });
testWidgets('MenuAnchor clip behavior', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: Material(
child: Center(
child: MenuAnchor(
menuChildren: const <Widget> [
MenuItemButton(
child: Text('Button 1'),
),
],
builder: (BuildContext context, MenuController controller, Widget? child) {
return FilledButton(
onPressed: () {
controller.open();
},
child: const Text('Tap me'),
);
},
),
)
)
)
);
await tester.tap(find.text('Tap me'));
await tester.pump();
// Test default clip behavior.
expect(getMenuBarMaterial(tester).clipBehavior, equals(Clip.hardEdge));
// Close the menu.
await tester.tapAt(const Offset(10.0, 10.0));
await tester.pumpAndSettle();
await tester.pumpWidget(
MaterialApp(
home: Material(
child: Center(
child: MenuAnchor(
clipBehavior: Clip.antiAlias,
menuChildren: const <Widget> [
MenuItemButton(
child: Text('Button 1'),
),
],
builder: (BuildContext context, MenuController controller, Widget? child) {
return FilledButton(
onPressed: () {
controller.open();
},
child: const Text('Tap me'),
);
},
),
)
)
)
);
await tester.tap(find.text('Tap me'));
await tester.pump();
// Test custom clip behavior.
expect(getMenuBarMaterial(tester).clipBehavior, equals(Clip.antiAlias));
});
testWidgets('open and close works', (WidgetTester tester) async { testWidgets('open and close works', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
...@@ -2057,7 +2118,7 @@ void main() { ...@@ -2057,7 +2118,7 @@ void main() {
'focusNode: null', 'focusNode: null',
'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)))', '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)))',
'alignmentOffset: null', 'alignmentOffset: null',
'clipBehavior: none', 'clipBehavior: hardEdge',
], ],
), ),
); );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment