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.
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.
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.
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.
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: () {},
),
)
],
),
)
try this out https://dartpad.dev/7ff7f5756d93db2d4ed6a4b9a6d75208. I used hack with wrapping in InkWell
the widget you want to surround with parent InkWell
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With