Wire up MenuAnchor clipBehaviour property (#123632)

Wire up MenuAnchor clipBehaviour property
This commit is contained in:
Henry Riehl 2023-03-30 18:11:26 +01:00 committed by GitHub
parent 8c5d223bab
commit 5f71179480
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 67 additions and 6 deletions

View file

@ -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(

View file

@ -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 <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 {
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',
],
),
);