MaterialStateMouseCursor class
Defines a MouseCursor whose value depends on a set of MaterialStates which represent the interactive state of a component.
This kind of MouseCursor is useful when the set of interactive actions a widget supports varies with its state. For example, a mouse pointer hovering over a disabled ListTile should not display SystemMouseCursors.click, since a disabled list tile doesn't respond to mouse clicks. ListTile's default mouse cursor is a MaterialStateMouseCursor.clickable, which resolves to SystemMouseCursors.basic when the button is disabled.
To use a MaterialStateMouseCursor, you should create a subclass of
MaterialStateMouseCursor and implement the abstract resolve
method.
flutter create --sample=material.MaterialStateMouseCursor.1 mysample
import 'package:flutter/rendering.dart';
// ...
class ListTileCursor extends MaterialStateMouseCursor {
@override
MouseCursor resolve(Set<MaterialState> states) {
if (states.contains(MaterialState.disabled)) {
return SystemMouseCursors.forbidden;
}
return SystemMouseCursors.click;
}
@override
String get debugDescription => 'ListTileCursor()';
}
// ...
Widget build(BuildContext context) {
return ListTile(
title: Text('Disabled ListTile'),
enabled: false,
mouseCursor: ListTileCursor(),
);
}
This class should only be used for parameters which are documented to take MaterialStateMouseCursor, otherwise only the default state will be used.
See also:
- MouseCursor for introduction on the mouse cursor system.
- SystemMouseCursors, which defines cursors that are supported by native platforms.
- Inheritance
- Object
- MouseCursor
- MaterialStateMouseCursor
- Implemented types
Constructors
- MaterialStateMouseCursor()
-
Creates a MaterialStateMouseCursor.
const
Properties
- debugDescription → String
-
A very short description of the mouse cursor. [...]
read-only, inherited
- hashCode → int
-
The hash code for this object. [...]
read-only, inherited
- runtimeType → Type
-
A representation of the runtime type of the object.
read-only, inherited
Methods
-
createSession(
int device ) → MouseCursorSession -
Associate a pointing device to this cursor. [...]
@protected, override
-
debugFillProperties(
DiagnosticPropertiesBuilder properties ) → void -
Add additional properties associated with the node. [...]
@mustCallSuper, @protected, inherited
-
noSuchMethod(
Invocation invocation ) → dynamic -
Invoked when a non-existent method or property is accessed. [...]
inherited
-
resolve(
Set< MaterialState> states) → MouseCursor -
Returns a MouseCursor that's to be used when a Material component is in
the specified state. [...]
override
-
toDiagnosticsNode(
{String name, DiagnosticsTreeStyle style} ) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep. [...]
inherited
-
toString(
{DiagnosticLevel minLevel: DiagnosticLevel.info} ) → String -
Returns a string representation of this object.
inherited
-
toStringShort(
) → String -
A brief description of this object, usually just the runtimeType and the
hashCode. [...]
inherited
Operators
-
operator ==(
Object other ) → bool -
The equality operator. [...]
inherited
Constants
- clickable → const MaterialStateMouseCursor
-
A mouse cursor for clickable material widgets, which resolves differently
when the widget is disabled. [...]
_EnabledAndDisabledMouseCursor(enabledCursor: SystemMouseCursors.click, disabledCursor: SystemMouseCursors.basic, name: 'clickable')
- textable → const MaterialStateMouseCursor
-
A mouse cursor for material widgets related to text, which resolves differently
when the widget is disabled. [...]
_EnabledAndDisabledMouseCursor(enabledCursor: SystemMouseCursors.text, disabledCursor: SystemMouseCursors.basic, name: 'textable')