Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Overlapping a transparent color with an icon on an image when a mouse is hovering on it

Good day,

I’m a beginner of Dart & Flutter, and have a challenge.

That is overlapping a transparent color with an icon on an image when a mouse is hovering on it.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can see what I want to make here:

enter image description here

Below are source codes I’m trying,

InkResponse(
  highlightShape: BoxShape.rectangle,
  containedInkWell: true,
  onHover: (isHovering) {
    if (isHovering) {
    // maybe input something here
    } else {
    // maybe input something here
    }
  },
  onTap: () => {showMyDialog()},
  child: Ink.image(
    width: 350.0,
    height: 280.0,
    fit: BoxFit.cover,
    image: Image.asset('images/technology.png').image,
  ),
)

Unfortunately I have no idea how to solve it.

Could you give me a hint or a solution?

It will be really appreciated.

>Solution :

First define a variable like this:

bool isHovered = false;

then in your build method change your InkResponse widget to this:

InkWell( 
        onHover: (isHovering) {
          setState(() {
            isHovered = isHovering;
          });
        },
        onTap: () => {},
        child: Stack(
          children: [
            Image(
              width: 350.0,
              height: 280.0,
              fit: BoxFit.cover,
              image: Image.asset('images/technology.png').image,
            ),
            isHovered
                ? Container(
                    width: 350.0,
                    height: 280.0,
                    color: Colors.red.withOpacity(0.4),
                    child: Icon(
                      Icons.add,
                      size: 34,
                      color: Colors.white,
                    ),
                  )
                : SizedBox(),
          ],
        ),
      )
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading