okaryo.log

Applying Tap Effect Within the Flutter Card's Boundary Using InkWell | okaryo.log

Applying Tap Effect Within the Flutter Card's Boundary Using InkWell

    #Flutter

Introduction

While developing personally using Flutter, there was a situation where I wanted to make the Card tappable.

I wanted to give it a tap effect, so I used InkWell. However, the tap effect protruded out of the Card and was displayed squarely.

Protruding tap effect

I’ll leave a note on how to apply the effect only within the range of the card.

Solution

By applying Clip.hardEdge to the clipBehavior property of the Card, you can apply the tap effect only within the range of the card.

Card(
  clipBehavior: Clip.hardEdge,
  child: InkWell(
    onTap: () {},
    child: SomeWidget(),
  ),
),

Tap effect only within the range

Points to Note

While Clip is an effective means in situations where elements protrude, like in this case, it’s said that there’s a performance cost when clipping elements.

If there are many elements to clip, or when performance is required, care should be taken.


Related Posts
Related Posts
Promotion

This site uses Google Analytics.