如何在Flutter中禁用FlatButton的高亮显示?

时间:2018-03-05 09:38:55

标签: android ios user-interface dart flutter

我有一个FlatButton。单击按钮时,我不想要启动突出显示。我尝试将飞溅颜色更改为透明,但这并不起作用。这是我的FlatButton的代码。

Widget button = new Container(
  child: new Container(
    padding: new EdgeInsets.only(bottom: 20.0),
    alignment: Alignment.center,
    child: new FlatButton(
      onPressed: () {
        _onClickSignInButton();
      },
      splashColor: Colors.transparent,
      child: new Stack(
        alignment: Alignment.center,
        children: <Widget>[
          new Image.asset('images/1.0x/button1.png',
          ),
          new Text("SIGN IN",
            style: new TextStyle(
                color: Colors.white,
                fontWeight: FontWeight.bold,
                fontSize: 16.0
              ),
          )
        ],
      ),
    ),
  ),
);

2 个答案:

答案 0 :(得分:6)

我期待一种看不见的高光颜色来做你想做的事情:

new FlatButton({
  ...
  splashColor: Colors.transparent,  
  highlightColor: Colors.transparent, // makes highlight invisible too
})

答案 1 :(得分:0)

由于 flatbuton 已折旧,而对于新的 textButton,我们有类似的东西。

TextButton(
   style: ButtonStyle(
   overlayColor: MaterialStateProperty.resolveWith<Color>(
  (Set<MaterialState> states) {
    if (states.contains(MaterialState.focused))
      return Colors.red;
    if (states.contains(MaterialState.hovered))
        return Colors.green;
    if (states.contains(MaterialState.pressed))
        return Colors.blue;
    return null; // Defer to the widget's default.
}),
),
 onPressed: () { },
 child: Text('TextButton with custom overlay colors'),
)