If you want to replace the mouse cursor with a custom widget, you could also follow this article.
In summary:
- Use a MouseRegion to hide the real cursor but still save its position with onHover
- Use a Stack and Positioned/AnimatedPositioned widget to add your custom cursor on top of the widget
// Use a stateful widget to record the cursor position
Offset position;
Widget build(BuildContext context) {
return MouseRegion(
cursor: SystemMouseCursors.none,
onHover: (event) {
setState(() {
// Save the position of the cursor when it moves
position = event.position;
});
},
child: Stack(
children: [
MyWidget(),
AnimatedPositioned(
duration: const Duration(milliseconds: 100),
left: position.dx,
top: position.dy,
child: CustomCursor(),
),
],
)
),
}