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
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.________),
),
)
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: () {},
)
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