Search code examples
flutterdartflutter-layout

Flutter 2.0 - How to change TextButton splash color when pressed?


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


Solution

  • TextButton(            
     style: ButtonStyle(
      overlayColor: MaterialStateColor.resolveWith((states) => Colors.red),
      ),
     child: ..., 
    )
    

    reference to Flutter TextButton splashColor property