Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter TextButton splashColor property

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

like image 595
user3808307 Avatar asked Oct 15 '20 23:10

user3808307


People also ask

How do I remove splash color from TextButton Flutter?

By setting both highlightColor and splashColor in your theme to Colors. transparent removed the ripple.

What is splashColor in Flutter?

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.

How do I change the splash color in button Flutter?

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.

What can I use instead of a FlatButton in Flutter?

The FlatButton , RaisedButton and OutlineButton widgets have been replaced by TextButton , ElevatedButton , and OutlinedButton respectively.

How to display overlay color in flutter textbutton?

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.

How do I set the splash color of a textbutton?

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:

Is it possible to use highlight color and splash color in flatbutton?

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

What is text button in flutter?

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.


5 Answers

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),
),
like image 83
dGoran Avatar answered Oct 19 '22 18:10

dGoran


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),
  ),
)
like image 30
Daniyal Dolare Avatar answered Oct 19 '22 20:10

Daniyal Dolare


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

like image 12
Balaji Avatar answered Oct 19 '22 20:10

Balaji


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
      }
      ...
    }),
  )
)
like image 3
GrayH Avatar answered Oct 19 '22 20:10

GrayH


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!

like image 1
ibc Avatar answered Oct 19 '22 19:10

ibc