我正在尝试在 Flutter 中创建一个凸起的“强调”按钮——也就是说,背景颜色与应用的强调主题相同。这是我的代码:
new RaisedButton(
onPressed: _signInPressed,
child: new Text('Sign in with Google'),
color: Theme.of(context).accentColor,
)
问题是文本颜色仍然是黑色。如何将文本颜色设置为白色,就像在 AppBar 中一样?
最佳答案
目前没有正式的方法来获取重音按钮。 你可以让自己拥有:
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,
);
}
}
关于flutter - 如何在 Flutter 中创建重音按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52435311/