Skip to content

Commit e02462a

Browse files
authored
CheckedPopupMenuItem: Fix cursor bug and add cursor parameter (#103474)
1 parent a27fcf1 commit e02462a

File tree

2 files changed

+89
-7
lines changed

2 files changed

+89
-7
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ class CheckedPopupMenuItem<T> extends PopupMenuItem<T> {
461461
super.enabled,
462462
super.padding,
463463
super.height,
464+
super.mouseCursor,
464465
super.child,
465466
}) : assert(checked != null);
466467

@@ -514,13 +515,15 @@ class _CheckedPopupMenuItemState<T> extends PopupMenuItemState<T, CheckedPopupMe
514515

515516
@override
516517
Widget buildChild() {
517-
return ListTile(
518-
enabled: widget.enabled,
519-
leading: FadeTransition(
520-
opacity: _opacity,
521-
child: Icon(_controller.isDismissed ? null : Icons.done),
518+
return IgnorePointer(
519+
child: ListTile(
520+
enabled: widget.enabled,
521+
leading: FadeTransition(
522+
opacity: _opacity,
523+
child: Icon(_controller.isDismissed ? null : Icons.done),
524+
),
525+
title: widget.child,
522526
),
523-
title: widget.child,
524527
);
525528
}
526529
}

packages/flutter/test/material/popup_menu_test.dart

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1620,7 +1620,6 @@ void main() {
16201620
);
16211621
});
16221622

1623-
16241623
testWidgets('CheckedPopupMenuItem custom padding', (WidgetTester tester) async {
16251624
final Key popupMenuButtonKey = UniqueKey();
16261625
final Type menuItemType = const CheckedPopupMenuItem<String>(child: Text('item')).runtimeType;
@@ -2092,6 +2091,86 @@ void main() {
20922091
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic);
20932092
});
20942093

2094+
testWidgets('CheckedPopupMenuItem changes mouse cursor when hovered', (WidgetTester tester) async {
2095+
const Key key = ValueKey<int>(1);
2096+
// Test CheckedPopupMenuItem() constructor
2097+
await tester.pumpWidget(
2098+
MaterialApp(
2099+
home: Scaffold(
2100+
body: Align(
2101+
alignment: Alignment.topLeft,
2102+
child: Material(
2103+
child: MouseRegion(
2104+
cursor: SystemMouseCursors.forbidden,
2105+
child: CheckedPopupMenuItem<int>(
2106+
key: key,
2107+
mouseCursor: SystemMouseCursors.text,
2108+
value: 1,
2109+
child: Container(),
2110+
),
2111+
),
2112+
),
2113+
),
2114+
),
2115+
),
2116+
);
2117+
2118+
final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse, pointer: 1);
2119+
await gesture.addPointer(location: tester.getCenter(find.byKey(key)));
2120+
addTearDown(gesture.removePointer);
2121+
2122+
await tester.pump();
2123+
2124+
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.text);
2125+
2126+
// Test default cursor
2127+
await tester.pumpWidget(
2128+
MaterialApp(
2129+
home: Scaffold(
2130+
body: Align(
2131+
alignment: Alignment.topLeft,
2132+
child: Material(
2133+
child: MouseRegion(
2134+
cursor: SystemMouseCursors.forbidden,
2135+
child: CheckedPopupMenuItem<int>(
2136+
key: key,
2137+
value: 1,
2138+
child: Container(),
2139+
),
2140+
),
2141+
),
2142+
),
2143+
),
2144+
),
2145+
);
2146+
2147+
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.click);
2148+
2149+
// Test default cursor when disabled
2150+
await tester.pumpWidget(
2151+
MaterialApp(
2152+
home: Scaffold(
2153+
body: Align(
2154+
alignment: Alignment.topLeft,
2155+
child: Material(
2156+
child: MouseRegion(
2157+
cursor: SystemMouseCursors.forbidden,
2158+
child: CheckedPopupMenuItem<int>(
2159+
key: key,
2160+
value: 1,
2161+
enabled: false,
2162+
child: Container(),
2163+
),
2164+
),
2165+
),
2166+
),
2167+
),
2168+
),
2169+
);
2170+
2171+
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic);
2172+
});
2173+
20952174
testWidgets('PopupMenu in AppBar does not overlap with the status bar', (WidgetTester tester) async {
20962175
const List<PopupMenuItem<int>> choices = <PopupMenuItem<int>>[
20972176
PopupMenuItem<int>(value: 1, child: Text('Item 1')),

0 commit comments

Comments
 (0)