簡體   English   中英

如何在Flutter中創建重音按鈕?

[英]How do I create an accent button in 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,
    );
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM