Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent ripple effect on surrounding InkWell when tapped on InkWell inside

Let's say that I have this widget:

Card(
  child: InkWell(
    onTap: () {},
    child: Padding(
      padding: const EdgeInsets.all(28.0),
      child: RaisedButton(
        child: Text('Test'),
        onPressed: () {},
      ),
    ),
  ),
),

I would like to disable (prevent showing) ripple effect on Card/InkWell only when the RaisedButton is tapped, but to show it when the Card is tapped (i.e. outside the button). Is there any way to achieve this effect?

I think the generalized question can be: How to prevent ripple effect on surrounding InkWell when tapped on InkWell inside? If you take a look at the source code then you can see that RaisedButton has Material and InkWell widgets that cause ripple.

Here is the full sample code.

enter image description here

like image 512
Dominik Roszkowski Avatar asked Oct 08 '19 10:10

Dominik Roszkowski


People also ask

What is the difference between InkWell and GestureDetector?

They both provide many common features like onTap , onLongPress etc. The main difference is GestureDetector provides more controls like dragging etc. on the other hand it doesn't include ripple effect tap, which InkWell does.

What is InkWell flutter?

InkWell class in Flutter is a rectangular area in Flutter of a material that responds to touch in an application. The InkWell widget must have a material widget as an ancestor. The material widget is where the ink reactions are actually performed. InkWell reactions respond when the user clicks the button.

How do I change InkWell ripple color?

The InkWell widget's color may be set via the color property of the Material widget. Using an opaque widget with images or decorations between the Material widget and InkWell widget will hide the ripple effect of an InkWell. The Ink widget can replace opaque widgets.


2 Answers

If you want a quick hack, check it out:

Container(
  width: 180,
  height: 120,
  child: Stack(
    children: <Widget>[
      Card(
        child: InkWell(
          onTap: () {},
        ),
      ),
      Center(
        child: RaisedButton(
          child: Text('Test'),
          onPressed: () {},
        ),
      )
    ],
  ),
)

enter image description here

like image 153
imaN NeoFighT Avatar answered Nov 08 '22 05:11

imaN NeoFighT


try this out https://dartpad.dev/7ff7f5756d93db2d4ed6a4b9a6d75208. I used hack with wrapping in InkWell the widget you want to surround with parent InkWell

like image 39
Ilya Maximencko Avatar answered Nov 08 '22 04:11

Ilya Maximencko