showMouse method
Shows the mouse cursor, optionally customizing its appearance with an image.
images: An optional Images list to use as the custom cursor. Ifnullor not provided, the default system cursor is shown.frame: The index of the image in theimageslist to use, if multiple frames are provided. Defaults to 0.
The hotspot of the custom cursor is determined by the pivotX and pivotY
properties of the selected Image.
Example:
late Images customPointer;
@override
void onCreate() {
customPointer = resources.loadImage("assets/pointer.png",
pivotX: 0.0
pivotY: 0.0
);
showMouse(customPointer);
}
Implementation
void showMouse([Images? images, int frame = 0]) async {
if (images == null) {
canvas.style.cursor = 'default';
} else {
var imageData = await encodeImageToDataURL(images, frame);
var cursorImage = images[frame];
int hotspotX = (cursorImage.pivotX * cursorImage.width).round();
int hotspotY = (cursorImage.pivotY * cursorImage.height).round();
canvas.style.cursor = 'url($imageData) $hotspotX $hotspotY, auto';
}
}