I was using FlatButton
and passed the properties
FlatButton(
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
child: ...,
)
The documentation says that FlatButton will become obsolete, and to use TextButton
instead, but it does not take splashColor
or highlightColor
properties
TextButton(
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
child: ...,
)
does not work. it is not allowed
I also tried like this
TextButton(
style: ButtonStyle(
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
),
child: ...,
)
How can I do this? Thank you
By setting both highlightColor and splashColor in your theme to Colors. transparent removed the ripple.
splashColor. The splash color of the button's InkWell. The ink splash indicates that the button has been touched. It appears on top of the button's child and spreads in an expanding circle beginning where the touch occurred.
Option 1: Set it in your app's ThemeData In your main. dart file, add ThemeData to your MaterialApp 's theme property (if it isn't already there). Within ThemeData , add the splashColor and highlightColor properties. The splashColor property is the color that spreads from the tap position.
The FlatButton , RaisedButton and OutlineButton widgets have been replaced by TextButton , ElevatedButton , and OutlinedButton respectively.
Flutter TextButton overlayColor We will use overlayColor property to display a color when the TextButton is pressed (down). It will start filling the button when it is in pressed (down)state and disappears when the button is released. For this purpose i’m using ButtonStyle () as styleFrom () don’t have overlayColor property.
You can quickly set the splash color of a TextButton using the helper method TextButton.styleFrom (). Note that this will actually set both the foreground color and splash color based on the foreground color, which in most of the cases is what you want:
FlatButton ( splashColor: Colors.transparent, highlightColor: Colors.transparent, child: ..., ) The documentation says that FlatButton will become obsolete, and to use TextButton instead, but it does not take splashColor or highlightColor properties
Flutter TextButton A text button is a label (child) displayed on a (zero elevation) Material widget. The label’s Text and Icon widgets are displayed in the style ‘s ButtonStyle.foregroundColor. The button reacts to touches by filling with the style’s ButtonStyle.backgroundColor.
Colors.transparent will deny any effects, simply it is transparent so it will appear as nothing happens... in ButtonStyle, it goes something like this with colors.
ButtonStyle(
overlayColor: MaterialStateColor.resolveWith((states) => Colors.red),
),
As Flat button is depricated, you have to use TextButton instead of it, but in text button there is no direct property to change splash color. So if you want to change splash color to transparent you can do it like this.
TextButton(
style: ButtonStyle(
overlayColor: MaterialStateProperty.all(Colors.transparent),
),
)
You can also use like this
TextButton( onPressed: () {},
style: TextButton.styleFrom(
backgroundColor: AppColors.primaryColor,
primary: Colors.black12),//ripple color
child:Text(AppLocalizations.of(context).startAdventure,
));
You can Set primary color to create ripple color
For someone who is not familiar to MaterialStateProperty
setting in TextButton (use resolveWith
to customize the button effect):
TextButton(
style: ButtonStyle(
overlayColor: MaterialStateColor.resolveWith((states) {
if(states.contains(MaterialState.hover){
return Colors.transparent; // <- hover color
}else if(states.contains(MaterialState.pressed){
return Colors.transparent; // <- ripple color
}
...
},
backgroundColor: MaterialStateColor.resolveWith((states) {
if(states.contains(MaterialState.pressed){
return Colors.transparent; // <- clicked color
}
...
}),
)
)
For Flutter over 3.1.0, where primary is deprecated, I change the spash color using:
style: TextButton.styleFrom(
backgroundColor: Colors.green, // Button color
foregroundColor: Colors.lime, // Splash color
),
child:Text(...)
In case it helps!
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