24

Flutter web cursor with hand pointer style

 4 years ago
source link: https://www.ernegonzal.com/flutter-web-cursor-with-hand-pointer-style/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Working with Flutter it is a pleasant experience. Easy, fast, productive, it just works.

We can create Flutter Apps for iOS and Android in an extremly short time. But even more, we can deliver a web based experience to the users.  not just mobile  “native”.

Goolge says Flutter web it is not ready for production . I believe so, there are still some missing features when it comes to making your App ready for the web.

But that does not mean that we can just use it and be aware of the little limitations we still have.

I have been working on a web based  project with Flutter.  The first issue I found is that the user does not have the same experience as on the web.

The issue

One thing you just notice straight away is that the mouse is not like in the standard web when hovering on clickable elements uA3aqiz.png!web .

It does not change to a little hand MZrMvqU.png!web to let you know you can click on it.

MZZj6zq.gif

Well, I wanted to deliver a web site! not a weird web!

So how can you make Flutter web look like a proper web showing the correct cursor style.

The Solution

Modify the index.html  giving an Id to the container.

<body id="flutter_container">

In your dart file:

Wrap your “clickable” widget into this MouseCursor widget that looks like this:

class MouseCursor extends MouseRegion{

  static var clickableArea = document.getElementById("flutter_container"); //your element id

  MouseCursor({@required Widget child}):super(
      child:child,
      onHover: _mouseOnHover,
       onExit: _mouseOnExit);

  static void _mouseOnHover(PointerHoverEvent event) {
      clickableArea.style.cursor = "pointer";
  }


  static void _mouseOnExit(PointerExitEvent event) {
    clickableArea.style.cursor = "default";
  }
}

So you should use it this way:

MouseCursor(child: TwitterHeart() ) );

NjIR3en.gif

That is it!  Easy right!?

If you like , you have any question or suggestions, please leave a comment or send me an email!

Happy coding with Flutter! :blue_heart:


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK