9
FlatButton is deprecated and shouldn't be used. Used TextButton instead.

On my previous FlatButton widget, I was able to changed the splash color when on pressed. But now I'm using TextButton widget, how can I change its color the efficient way on the MaterialApp ThemeData or directly on the TextButton widget.

Currenly this is my TextButton

TextButton(
  style: TextButton.styleFrom(
    primary: Colors.red,
    textStyle: TextStyle(
      color: Colors.black45,
      fontFamily: "Courier Prime",
    ),
    backgroundColor: Colors.transparent,
  ),
  onPressed: () {},
  child: Text(
    "Student",
    style: TextStyle(fontWeight: FontWeight.bold),
  ),
),
overlayColor is used to indicate that the button is focused, hovered, or pressed.

But I cant find this overlayColor

NearHuscarl
  • 66,950
  • 18
  • 261
  • 230
Raine Dale Holgado
  • 2,932
  • 2
  • 17
  • 32

4 Answers4

9

First keep in mind that the primary property on a TextButton sets the colour of its text and icon. It does not change the ripple color. Secondly in Textbutton 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.________),
  ),
)
Arslan Kaleem
  • 1,410
  • 11
  • 25
6

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:

TextButton(
  style: TextButton.styleFrom(primary: Colors.red),
  child: const Text('Text Button'),
  onPressed: () {},
)

Live Demo

NearHuscarl
  • 66,950
  • 18
  • 261
  • 230
4
TextButton(            
 style: ButtonStyle(
  overlayColor: MaterialStateColor.resolveWith((states) => Colors.red),
  ),
 child: ..., 
)

reference to Flutter TextButton splashColor property

s.am.i
  • 648
  • 5
  • 16
0

You can change Splash color like this:

            Theme(
              data: ThemeData(
                splashColor: Colors.red,
                highlightColor: Colors.black.withOpacity(.5),
              ),
              child: ListTile(
                  title: Text(
                    "New theme splash",
                    textAlign: TextAlign.center,
                  ),
                  onTap: () {}),
            ),
Adam Smaka
  • 5,977
  • 3
  • 50
  • 55