从 Flutter 中的 RaisedButton 移除阴影

Roc*_*nat 2 flutter flutter-layout

有没有办法完全去除下的阴影RaisedButton?我已经设置 elevation: 0为非常RaisedButton但点击它时仍然出现阴影。

Nit*_*esh 26

由于凸起按钮已被弃用。

ElevatedButton(
                style: ElevatedButton.styleFrom(
                  elevation: 0.0,
                  shadowColor: Colors.transparent,
               
                ),),
Run Code Online (Sandbox Code Playgroud)

这应该是解决方案。它将删除高程和阴影。

  • 这是行不通的 (2认同)

Roc*_*nat 9

RaisedButton有四个不同的elevation参数。只需将它们全部设置为 0。

elevation: 0,
hoverElevation: 0,
focusElevation: 0,
highlightElevation: 0,
Run Code Online (Sandbox Code Playgroud)

  • 我刚想写这个答案。 (2认同)
  • diabledElevation 也可以,或者您可以使用 [FlatButton](/sf/ask/2067296871/) (2认同)

jes*_*ikr 5

由于 RaisingButton 已被弃用,应使用 ElevatedButton,因此该问题的解决方案也很简单。

elevation: MaterialStateProperty.all<double>(0)
Run Code Online (Sandbox Code Playgroud)


小智 5

您可以在这里找到答案: https ://api.flutter.dev/flutter/material/ButtonStyle-class.html

你必须使用:

.copyWith(elevation:ButtonStyleButton.allOrNull(0.0))


//Example

ElevatedButton(
        child: Text("Your Text"),
        onPressed: onPressed,
        style: ElevatedButton.styleFrom(
          backgroundColor: Color.fromRGBO(255, 255, 255, 1),
          foregroundColor: Colors.black54,
          shadowColor: Colors.transparent,
          elevation: 0.0,
        ).copyWith(elevation:ButtonStyleButton.allOrNull(0.0))
Run Code Online (Sandbox Code Playgroud)