Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter-Web: Mouse hover -> Change cursor to pointer

UPDATE (2021/05/11):

Flutter now natively has Hover Events implemented Widgets.

There is a MouseCursor for Widgets like RaisedButton and properties like hoverColor or hoverElevation.

https://api.flutter.dev/flutter/rendering/MouseCursor-class.html

You can also use an InkWell anywhere else as stated in the accepted answer.


Original Question:

How can the cursor appearance be changed within Flutter? I know that with the Listener() Widget we can listen for Mouse-Events, but I haven't found any information regarding hovering events for flutter web. Has someone found a soulution yet?

like image 507
Daniel Eberl Avatar asked May 19 '19 20:05

Daniel Eberl


People also ask

How do I change my cursor when hovering?

How to Change the Cursor of Hyperlink while Hovering. The default cursor for a hyperlink is "pointer". To change it, you need to specify the cursor type for your <a> element with the CSS :hover selector. In our example, we style only the "link" class.

How do you change the cursor into a hand when a user hovers over a list item?

How to make the cursor to hand when a user hovers over a list item using CSS? Use CSS property to create cursor to hand when user hovers over the list of items. First create list of items using HTML <ul> and <li> tag and then use CSS property :hover to cursor:grab; to make cursor to hand hover the list of items.

How do you hover in flutter?

The hover effect library gives a 3d hover effect like any box or container etc. we rotate it around the top, bottom, left, right so it is 3d changes its position in style, in this, we can change its shadow color, depthColor etc.


1 Answers

I had difficulties finding documentation on the now built-in support. Here is what helped me: https://github.com/flutter/flutter/issues/58260

And this did the trick for me, without changing index.html etc.

MouseRegion(   cursor: SystemMouseCursors.click,     child: GestureDetector(       child: Icon(         Icons.add_comment,         size: 20,         ),       onTap: () {},     ),   ), 

Also see the official documentation: https://api.flutter.dev/flutter/rendering/MouseCursor-class.html

Widget build(BuildContext context) {   return Center(     child: MouseRegion(       cursor: SystemMouseCursors.text,       child: Container(         width: 200,         height: 100,         decoration: BoxDecoration(           color: Colors.blue,           border: Border.all(color: Colors.yellow),         ),       ),     ),   ); } 

And here https://api.flutter.dev/flutter/material/MaterialStateMouseCursor-class.html yet another wonderful example from the official docs that "...defines a mouse cursor that resolves to SystemMouseCursors.forbidden when its widget is disabled."

like image 127
beneM Avatar answered Sep 18 '22 10:09

beneM