FlatButton is deprecated and shouldn't be used. Used TextButton instead.
字符串
在我以前的FlatButton
小部件上,我可以在按下时更改启动颜色。但现在我使用的是TextButton
小部件,我如何在MaterialApp ThemeData
上或直接在TextButton
小部件上有效地更改其颜色?
这是我的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.
但我找不到这个overlayColor
5条答案
按热度按时间xfyts7mz1#
字符串
引用Flutter TextButton splashColor property
4ngedf3f2#
您可以像这样更改飞溅颜色:
字符串
zc0qhyus3#
我更喜欢NearHuscarl's Anser。但是在flutter v3.1.0之后,你可以实现像
字符串
eeq64g8w4#
首先要记住,TextButton上的primary属性设置了文本和图标的颜色。它不会改变涟漪颜色。其次,在TextButton中没有直接的属性来改变飞溅颜色。所以如果你想将飞溅颜色改为透明,你可以这样做。
字符串
p4rjhz4m5#
您可以使用辅助方法
TextButton.styleFrom()
快速设置TextButton
的启动颜色。请注意,这实际上将根据前景色设置前景色和启动颜色,这在大多数情况下都是您想要的:字符串
Live Demo