From 5f7117948072cbbda85348ae62a836fd514a395a Mon Sep 17 00:00:00 2001 From: Henry Riehl <73116038+whiskeyPeak@users.noreply.github.com> Date: Thu, 30 Mar 2023 18:11:26 +0100 Subject: [PATCH] Wire up MenuAnchor clipBehaviour property (#123632) Wire up MenuAnchor clipBehaviour property --- .../flutter/lib/src/material/menu_anchor.dart | 10 +-- .../test/material/menu_anchor_test.dart | 63 ++++++++++++++++++- 2 files changed, 67 insertions(+), 6 deletions(-) diff --git a/packages/flutter/lib/src/material/menu_anchor.dart b/packages/flutter/lib/src/material/menu_anchor.dart index 77838b8f26..5b0c17f017 100644 --- a/packages/flutter/lib/src/material/menu_anchor.dart +++ b/packages/flutter/lib/src/material/menu_anchor.dart @@ -127,7 +127,7 @@ class MenuAnchor extends StatefulWidget { this.childFocusNode, this.style, this.alignmentOffset = Offset.zero, - this.clipBehavior = Clip.none, + this.clipBehavior = Clip.hardEdge, this.anchorTapClosesMenu = false, this.onOpen, this.onClose, @@ -183,7 +183,7 @@ class MenuAnchor extends StatefulWidget { /// {@macro flutter.material.Material.clipBehavior} /// - /// Defaults to [Clip.none]. + /// Defaults to [Clip.hardEdge]. final Clip clipBehavior; /// Whether the menus will be closed if the anchor area is tapped. @@ -1530,7 +1530,7 @@ class SubmenuButton extends StatefulWidget { this.style, this.menuStyle, this.alignmentOffset, - this.clipBehavior = Clip.none, + this.clipBehavior = Clip.hardEdge, this.focusNode, this.statesController, this.leadingIcon, @@ -1584,7 +1584,7 @@ class SubmenuButton extends StatefulWidget { /// {@macro flutter.material.Material.clipBehavior} /// - /// Defaults to [Clip.none]. + /// Defaults to [Clip.hardEdge]. final Clip clipBehavior; /// {@macro flutter.widgets.Focus.focusNode} @@ -3312,7 +3312,7 @@ class _MenuPanelState extends State<_MenuPanel> { shadowColor: shadowColor, surfaceTintColor: surfaceTintColor, type: backgroundColor == null ? MaterialType.transparency : MaterialType.canvas, - clipBehavior: Clip.hardEdge, + clipBehavior: widget.clipBehavior, child: Padding( padding: resolvedPadding, child: SingleChildScrollView( diff --git a/packages/flutter/test/material/menu_anchor_test.dart b/packages/flutter/test/material/menu_anchor_test.dart index 655eaded90..e23e102aee 100644 --- a/packages/flutter/test/material/menu_anchor_test.dart +++ b/packages/flutter/test/material/menu_anchor_test.dart @@ -945,6 +945,67 @@ void main() { 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 [ + 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 [ + 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 { await tester.pumpWidget( MaterialApp( @@ -2057,7 +2118,7 @@ void main() { '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)))', 'alignmentOffset: null', - 'clipBehavior: none', + 'clipBehavior: hardEdge', ], ), );