mouseCursor property
The cursor for a mouse pointer when it enters or is hovering over the widget.
Resolved in the following states:
This example resolves the mouseCursor based on the current WidgetState of the CupertinoSwitch, providing a different mouseCursor when it is WidgetState.disabled.
CupertinoSwitch(
value: true,
onChanged: (bool value) { },
mouseCursor: WidgetStateProperty.resolveWith<MouseCursor>((Set<WidgetState> states) {
if (states.contains(WidgetState.disabled)) {
return SystemMouseCursors.click;
}
return SystemMouseCursors.basic; // All other states will use the default mouseCursor.
}),
)
If null, then MouseCursor.defer is used when the switch is disabled. When the switch is enabled, SystemMouseCursors.click is used on Web, and MouseCursor.defer is used on other platforms.
See also:
- WidgetStateMouseCursor, a MouseCursor that implements
WidgetStatePropertywhich is used in APIs that need to accept either a MouseCursor or a WidgetStateProperty.
Implementation
// TODO(framework): Add unit tests to this code snippet.
// https://github.com/flutter/flutter/issues/188530
///
/// This example resolves the [mouseCursor] based on the current
/// [WidgetState] of the [CupertinoSwitch], providing a different [mouseCursor] when it is
/// [WidgetState.disabled].
///
/// ```dart
/// CupertinoSwitch(
/// value: true,
/// onChanged: (bool value) { },
/// mouseCursor: WidgetStateProperty.resolveWith<MouseCursor>((Set<WidgetState> states) {
/// if (states.contains(WidgetState.disabled)) {
/// return SystemMouseCursors.click;
/// }
/// return SystemMouseCursors.basic; // All other states will use the default mouseCursor.
/// }),
/// )
/// ```
///
/// </callout-box>
///
/// If null, then [MouseCursor.defer] is used when the switch is disabled.
/// When the switch is enabled, [SystemMouseCursors.click] is used on Web, and
/// [MouseCursor.defer] is used on other platforms.
///
/// See also:
///
/// * [WidgetStateMouseCursor], a [MouseCursor] that implements
/// `WidgetStateProperty` which is used in APIs that need to accept
/// either a [MouseCursor] or a [WidgetStateProperty].
final WidgetStateProperty<MouseCursor>? mouseCursor;