@@ -90,6 +90,7 @@ class CupertinoButton extends StatefulWidget {
90
90
this .focusNode,
91
91
this .onFocusChange,
92
92
this .autofocus = false ,
93
+ this .mouseCursor,
93
94
this .onLongPress,
94
95
required this .onPressed,
95
96
}) : assert (pressedOpacity == null || (pressedOpacity >= 0.0 && pressedOpacity <= 1.0 )),
@@ -125,6 +126,7 @@ class CupertinoButton extends StatefulWidget {
125
126
this .focusNode,
126
127
this .onFocusChange,
127
128
this .autofocus = false ,
129
+ this .mouseCursor,
128
130
this .onLongPress,
129
131
required this .onPressed,
130
132
}) : assert (minimumSize == null || minSize == null ),
@@ -154,6 +156,7 @@ class CupertinoButton extends StatefulWidget {
154
156
this .focusNode,
155
157
this .onFocusChange,
156
158
this .autofocus = false ,
159
+ this .mouseCursor,
157
160
this .onLongPress,
158
161
required this .onPressed,
159
162
}) : assert (pressedOpacity == null || (pressedOpacity >= 0.0 && pressedOpacity <= 1.0 )),
@@ -258,6 +261,23 @@ class CupertinoButton extends StatefulWidget {
258
261
/// {@macro flutter.widgets.Focus.autofocus}
259
262
final bool autofocus;
260
263
264
+ /// The cursor for a mouse pointer when it enters or is hovering over the widget.
265
+ ///
266
+ /// If [mouseCursor] is a [WidgetStateMouseCursor] ,
267
+ /// [WidgetStateProperty.resolve] is used for the following [WidgetState] :
268
+ /// * [WidgetState.disabled] .
269
+ ///
270
+ /// If null, then [MouseCursor.defer] is used when the button is disabled.
271
+ /// When the button is enabled, [SystemMouseCursors.click] is used on Web
272
+ /// and [MouseCursor.defer] is used on other platforms.
273
+ ///
274
+ /// See also:
275
+ ///
276
+ /// * [WidgetStateMouseCursor] , a [MouseCursor] that implements
277
+ /// [WidgetStateProperty] which is used in APIs that need to accept
278
+ /// either a [MouseCursor] or a [WidgetStateProperty].
279
+ final MouseCursor ? mouseCursor;
280
+
261
281
final _CupertinoButtonStyle _style;
262
282
263
283
/// Whether the button is enabled or disabled. Buttons are disabled by default. To
@@ -297,6 +317,13 @@ class _CupertinoButtonState extends State<CupertinoButton> with SingleTickerProv
297
317
298
318
late bool isFocused;
299
319
320
+ static final WidgetStateProperty <MouseCursor > _defaultCursor =
321
+ WidgetStateProperty .resolveWith <MouseCursor >((Set <WidgetState > states) {
322
+ return ! states.contains (WidgetState .disabled) && kIsWeb
323
+ ? SystemMouseCursors .click
324
+ : MouseCursor .defer;
325
+ });
326
+
300
327
@override
301
328
void initState () {
302
329
super .initState ();
@@ -459,9 +486,16 @@ class _CupertinoButtonState extends State<CupertinoButton> with SingleTickerProv
459
486
size:
460
487
textStyle.fontSize != null ? textStyle.fontSize! * 1.2 : kCupertinoButtonDefaultIconSize,
461
488
);
489
+
462
490
final DeviceGestureSettings ? gestureSettings = MediaQuery .maybeGestureSettingsOf (context);
491
+
492
+ final Set <WidgetState > states = < WidgetState > {if (! enabled) WidgetState .disabled};
493
+ final MouseCursor effectiveMouseCursor =
494
+ WidgetStateProperty .resolveAs <MouseCursor ?>(widget.mouseCursor, states) ??
495
+ _defaultCursor.resolve (states);
496
+
463
497
return MouseRegion (
464
- cursor: enabled && kIsWeb ? SystemMouseCursors .click : MouseCursor .defer ,
498
+ cursor: effectiveMouseCursor ,
465
499
child: FocusableActionDetector (
466
500
actions: _actionMap,
467
501
focusNode: widget.focusNode,
0 commit comments