Flutter - Programmatically change the mouse cursor without rebuilding the widget. Setting cursor in a RenderBox?

266 views Asked by At

The most common use to change the cursor is through MouseRegion and setState. Example:

MouseRegion(cursor: _myCursor);

setState(() {
  if(...) {
    _myCursor = SystemMouseCursors.copy;
  } else {
    _myCursor = SystemMouseCursors.move;
  }
});

Is there a way to make this change without rebuilding the Widget? The CustomPaint, for example, accepts a Listening that, when triggered, will only notify a new repaint without rebuild.

Maybe if it were possible to set the mouse cursor inside a RenderBox. I could create one replicating the behavior of CustomPaint using a Listening and markNeedsPaint method.

Has anyone already configured the cursor inside the RenderBox?

1

There are 1 answers

1
Carlos Eduardo On

Studying RenderMouseRegion, I figure out that your custom RenderBox needs to implement MouseTrackerAnnotation to change the cursor. The hitTest must return TRUE.