Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to animate images on mouse hover using Flutter for Web?

I am a JavaScript developer and I am new to Flutter. I just want to animate a set of images on mouse hover like this using Flutter for Web. It includes Scaling, Opacity and Grayscale transformations. How to accomplish this in Flutter? Thanks in advance.

like image 989
Giri Avatar asked Feb 04 '20 15:02

Giri


People also ask

How do I hover an image in flutter?

You just need to install the package running this command flutter pub add hovering or adding hovering: ^1.0. 4 to your dependencies. Then you can use HoverWidget , HoverContainer , HoverAnimatedContainer , and some more. It's not perfect, but it's an easy way to do it, specially for not complicated animations.

How do you do a hover effect 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

Other than the animation part of your question. The onHover argument of the InkWell only works if you specify the onTap argument first.

InkWell(
  child: SomeWidget(),
  onTap: () {
    //You can leave it empty, like that.
  }
  onHover: (isHovering) {
    if (isHovering) {
      //The mouse is hovering.
    } else {
      //The mouse is no longer hovering.
    }
  }
)

From the documentation, here's the benefit of the boolean, which is passed to the onHover callback:

The value passed to the callback is true if a pointer has entered this part of the material and false if a pointer has exited this part of the material.

like image 130
Tayan Avatar answered Sep 26 '22 14:09

Tayan