[英]How do I create an accent button in Flutter?
I'm trying to create a raised 'accent' button in Flutter - that is, with the background the same color as the app's accent theme. 我正在尝试在Flutter中创建一个凸起的“重音”按钮-也就是说,背景颜色与该应用的重音主题相同。 Here's my code: 这是我的代码:
new RaisedButton(
onPressed: _signInPressed,
child: new Text('Sign in with Google'),
color: Theme.of(context).accentColor,
)
Problem is the text color is still black. 问题是文本颜色仍然是黑色。 How do I set the text color to be white like in the AppBar? 如何在AppBar中将文本颜色设置为白色?
There's currently no official way to get accent button. 目前尚无官方获取重音按钮的方法。 You can make you own though: 您可以通过以下方式使自己拥有:
class AccentButton extends StatelessWidget {
final VoidCallback onPressed;
final Widget child;
const AccentButton({this.child, this.onPressed, Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return RaisedButton(
onPressed: onPressed,
child: child,
textColor: theme.accentTextTheme.button.color,
highlightColor: theme.accentColor,
color: theme.accentColor,
);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.