如何在Flutter中禁用FlatButton的启动突出显示?

Cha*_*air 15 user-interface android ios 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
              ),
          )
        ],
      ),
    ),
  ),
);
Run Code Online (Sandbox Code Playgroud)

Gün*_*uer 22

我希望使用一种不可见的高光颜色来完成您想要的工作:

new FlatButton({
  ...
  splashColor: Colors.transparent,  
  highlightColor: Colors.transparent, // makes highlight invisible too
})
Run Code Online (Sandbox Code Playgroud)

  • 这也适用于 IconButton。 (2认同)

Dee*_*tty 13

由于 flatbutton 已被折旧,对于新的 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'),
)
Run Code Online (Sandbox Code Playgroud)


tfm*_*gue 8

FlatButton在 Flutter v1.26 中已弃用 ( https://api.flutter.dev/flutter/material/FlatButton-class.html )。

使用TextButtonoverlayColor财产。

TextButton(
  style: ButtonStyle(
    overlayColor: MaterialStateProperty.all(Colors.transparent)
  )
)
Run Code Online (Sandbox Code Playgroud)