This PR is for issue #154792 The Video recording shows the before and after The first button with the text "Go" uses the default cursor The second button with the text "With Cursor" uses a custom cursor that has been passed in the parameters https://github.com/user-attachments/assets/e82ecd42-42b1-42c9-aa30-a6f3daddb436 Here is the code for the second button ```dart CupertinoButton( onPressed: () { showCupertinoModalPopup<void>( context: context, builder: (BuildContext context) { return CupertinoActionSheet( title: const Text('The title'), message: const Text('Message'), actions: <Widget>[ CupertinoActionSheetAction( cursor: SystemMouseCursors.forbidden, child: const Text('One'), onPressed: () {}, ), ], ); }, ); }, child: const Text('With Cursor'), ), ``` Fixes https://github.com/flutter/flutter/issues/154792
This commit is contained in:
parent
5f93a7f7ea
commit
1a31e396db
@ -1215,6 +1215,7 @@ class CupertinoActionSheetAction extends StatefulWidget {
|
||||
required this.onPressed,
|
||||
this.isDefaultAction = false,
|
||||
this.isDestructiveAction = false,
|
||||
this.mouseCursor,
|
||||
required this.child,
|
||||
});
|
||||
|
||||
@ -1234,6 +1235,12 @@ class CupertinoActionSheetAction extends StatefulWidget {
|
||||
/// Destructive buttons have red text.
|
||||
final bool isDestructiveAction;
|
||||
|
||||
/// The cursor that will be shown when hovering over the button.
|
||||
///
|
||||
/// If null, defaults to [SystemMouseCursors.click] on web and
|
||||
/// [MouseCursor.defer] on other platforms.
|
||||
final MouseCursor? mouseCursor;
|
||||
|
||||
/// The widget below this widget in the tree.
|
||||
///
|
||||
/// Typically a [Text] widget.
|
||||
@ -1312,7 +1319,7 @@ class _CupertinoActionSheetActionState extends State<CupertinoActionSheetAction>
|
||||
+ fontSize * _kActionSheetButtonVerticalPaddingFactor;
|
||||
|
||||
return MouseRegion(
|
||||
cursor: kIsWeb ? SystemMouseCursors.click : MouseCursor.defer,
|
||||
cursor: widget.mouseCursor ?? (kIsWeb ? SystemMouseCursors.click : MouseCursor.defer),
|
||||
child: MetaData(
|
||||
metaData: this,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
|
@ -1956,6 +1956,44 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('CupertinoActionSheet action cursor behavior', (WidgetTester tester) async {
|
||||
const SystemMouseCursor customCursor = SystemMouseCursors.grab;
|
||||
|
||||
await tester.pumpWidget(
|
||||
createAppWithButtonThatLaunchesActionSheet(
|
||||
CupertinoActionSheet(
|
||||
title: const Text('The title'),
|
||||
message: const Text('Message'),
|
||||
actions: <Widget>[
|
||||
CupertinoActionSheetAction(
|
||||
mouseCursor: customCursor,
|
||||
onPressed: () { },
|
||||
child: const Text('One'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text('Go'));
|
||||
await tester.pump();
|
||||
|
||||
final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse, pointer: 1);
|
||||
await gesture.addPointer(location: const Offset(10, 10));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1),
|
||||
SystemMouseCursors.basic,
|
||||
);
|
||||
|
||||
final Offset actionSheetAction = tester.getCenter(find.text('One'));
|
||||
await gesture.moveTo(actionSheetAction);
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1),
|
||||
customCursor,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('Action sheets emits haptic vibration on sliding into a button', (WidgetTester tester) async {
|
||||
int vibrationCount = 0;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user