Flutter InkWell widget not showing through a container's gradient and color
The easiest solution is to use a Material
widget as parent of the InkWell
and set its color
to transparent. The InkWell
must be set on the card only (in your example the GestureDetector
is set on the whole column). To fit the exact shape, the InkWell
gets the same borderRadius
as your Card (Container)
Here is a solution of your build method. I placed the InkWell
and Materal
widget as parent of the Center
widget
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
Container(
width: 75.0,
height: 75.0,
child: Material(
color: Colors.transparent,
child: InkWell(
onTap: onPress,
borderRadius: BorderRadius.circular(15.0),
splashColor: Colors.grey[500],
child: Center(
child: Text(
cardText,
style: TextStyle(
color: Colors.white,
fontFamily: 'Circular STD',
fontWeight: FontWeight.w900,
fontSize: 20.0,
),
),
),
),
),
...
Rohan
Updated on December 19, 2022Comments
-
Rohan over 1 year
EDIT: I've tried wrapping the
Container
in aMaterial
widget and moving the color property to theMaterial
widget, but I'm placing a bunch ofResourceCards
in a horizontalListView,
so the color from theMaterial
widget seems to only fill the space around theResourceCard
.I've created my own widget
ResourceCard
in Flutter. I wrapped it with aGestureDetector
to detect taps, but I want to show some sort of feedback or effect to notify the user that it was tapped. I decided to replace theGestureDetector
with anInkWell
widget, but I don't see the splash effect through the container's linear-gradient and colour, so I just reverted it back to aGestureDetector
. I've seen other posts with potential workarounds, but none of them work with a linear gradient and color. Here's what one of theResourceCard
widgets look like: https://imgur.com/dg3fu9e. Here's the widget's code:class ResourceCard extends StatelessWidget { ResourceCard({ @required this.colour, @required this.margin, @required this.cardText, this.onPress, @required this.cardCaption, @required this.paddingText, }); final Color colour; final String cardText; final Function onPress; final EdgeInsets margin; final String cardCaption; final EdgeInsets paddingText; @override Widget build(BuildContext context) { return GestureDetector( onTap: onPress, child: Column( children: <Widget>[ Container( width: 75.0, height: 75.0, child: Center( child: Text( cardText, style: TextStyle( color: Colors.white, fontFamily: 'Circular STD', fontWeight: FontWeight.w900, fontSize: 20.0, ), ), ), margin: margin, decoration: BoxDecoration( gradient: LinearGradient( begin: Alignment.topRight, end: Alignment.bottomLeft, colors: [colour, Colors.blue], ), color: colour, borderRadius: BorderRadius.circular(15.0), boxShadow: [ BoxShadow( color: Color.fromRGBO(0, 0, 0, 0.5), blurRadius: 10.0, spreadRadius: 1.0, ) ], ), ), Padding( padding: paddingText, child: Text( cardCaption, textAlign: TextAlign.center, style: TextStyle( color: Colors.white70, fontWeight: FontWeight.w300, fontSize: 10.0, fontFamily: 'Circular STD', ), ), ), ], ), ); } }
-
Manuel about 4 yearsJust to make sure: You want the splash effect from the InkWell over the hole card, not only the rounded container with the gradient?
-
pskink about 4 yearssee api.flutter.dev/flutter/material/InkWell-class.html and check
Troubleshooting
section -
Rohan about 4 years@Manuel I wanted the InkWell splash to only show up on the card (the rounded container with a couple letters inside of it), not the text underneath. Essentially, I want it to act like a FlatButton.
-
-
Moralde-Sama over 3 yearsdoes not work on me if I include decoration on container
-
Ittai Barkai over 2 years@Moralde-Sama wrap InkWell with an Ink widget, which has a decoration parameter