flutter - 如何在 Flutter 中创建重音按钮?

标签 flutter

我正在尝试在 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/

相关文章:

android - 使用 Flutter 将图像上传到通用 Google Drive 帐户

flutter - 如何从目录导入所有 Dart 文件?

flutter - 我可以在其他小部件的 PageView 小部件中使用 'index' 吗?

Flutter integration_test - 制作截图

javascript - 如何通过在 flutter 中知道其值来删除 key ?

flutter - flutter 具有多个floatActionButtons

flutter - Flutter 中的嵌套路由浏览器 URL

flutter - 如何在 Flutter 中更改子树的文本颜色?

json - Dart- 'String'类型不是 'Iterable<dynamic>'类型的子类型

flutter - 未处理的异常 : FileSystemException: Cannot open file, 路径 = 'assets/xml/strings.xml'(操作系统错误 : No such file or directory, errno = 2)