MouseRegion Widget

For mouse movements, you may use the MouseRegion widget. A widget that tracks the movement of mice, even when no button is pressed.

It does not listen to events that can construct gestures, such as when the pointer is pressed, moved, then released or canceled. For these events, use Listener, or more preferably, GestureDetector. When you want to detect for wheel scrolling events, you may use the Listener widget

If it has a child, this widget defers to the child for sizing behavior. If it does not have a child, it grows to fit the parent instead.

Properties

onEnter

Called when a mouse pointer has entered this widget.

onExit

Called when a mouse pointer has exited this widget when the widget is still mounted.

onHover

Called when a mouse pointer moves within this widget without buttons pressed.

MouseRegion(
  onEnter: (PointerEnterEvent event) {
    print('x: ${event.position.dx}, y: ${event.position.dy}');
  },
  onHover: (PointerHoverEvent event) {
    print('x: ${event.position.dx}, y: ${event.position.dy}');
  },
  onExit: (PointerExitEvent event) {
    print('x: ${event.position.dx}, y: ${event.position.dy}');
  },
  child: child,
)