I am trying to make my Image.asset()
in Flutter have a ripple effect whenever the image is tapped
Below are my image assets
Image.asset('images/ic_close.png')
I have tried placing it inside InkWell
and providing a splash color but it’s also not working. Below is how I have tried to achieve a ripple effect using InkWell
InkWell(
splashColor: Colors.black87,
onTap: () {
Navigator.pop(context);
},
child: Image.asset('images/ic_close.png'),
)
2
Answers
You have to wrap your Inkwell also with transparent Material widget. If your Image have no background, it will work like this (because you see it through its transparent parts):
If you want to overlay your full image, I only found a ways with stack. Like:
To get a ripple effect, you need to use the
Ink.image
constructor.But The problem is that
Ink.image
doesn’t have anonTap
. so, let’s create our own reusable widget that supports anonTap
:Usage: