flutter_hooks icon indicating copy to clipboard operation
flutter_hooks copied to clipboard

Add support for various mouse APIs, `useMouseOver`, 'useMouseOffset', etc

Open esDotDev opened this issue 4 years ago • 4 comments
trafficstars

Is your feature request related to a problem? Please describe. It's cumbersome to manually create desktop effects for the mouse cursor. We need to either use a StatefulWidget w/ MouseRegion widget 2 event listeners, and an internal _isMouseDown bool, or some combination of nested Build widgets.

Similarly, getting the mouse position is a fairly verbose process of using MouseRegion, some local Offset, and maybe a globalToLocal call on the context.

Describe the solution you'd like bool isMouseOver = useMouseOver(); Offset mousePos = useMouseOffset(); Offset localMousePos = useMouseOffset(local: true);

esDotDev avatar Dec 21 '20 22:12 esDotDev

It's feasible but needs adding support for mounting RenderObjects using hooks.

Doable, but requires a bit of work.

rrousselGit avatar Dec 22 '20 21:12 rrousselGit

Nice! I took a stab at it, but am really out of my depth when trying to use gesture detection manually without a widget. Cant find a clear code example anywhere on how this would actually be setup.

esDotDev avatar Dec 22 '20 22:12 esDotDev

It's feasible but needs adding support for mounting RenderObjects using hooks.

Doable, but requires a bit of work.

Would such addition provide the possibility to create a hook like useConstraints, the equivalent to a LayoutBuilder? That would be very useful for responsive UI related hooks and extract common logic in the app.

For example a custom hook like: useAvailableSpace(). It could return an enum (narrow, medium, wide) by using the constraints hook under the hood.

davidmartos96 avatar Feb 06 '21 00:02 davidmartos96

LayoutBuilder is special

I don't think it's feasible to implement as a hook. The main issue is, it invokes its builder asynchronously. So hooks wouldn't be able to synchronously get the value

rrousselGit avatar Feb 06 '21 18:02 rrousselGit