You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何去除Flutter中ElevatedButton的边框?

如何去除ElevatedButton的边框?

升级SDK版本后,FlatButton、RaisedButton等旧控件无法使用,改用ElevatedButton后需要去除其边框,你当前的代码如下:

ElevatedButton(
              style: ElevatedButton.styleFrom(
                primary: Colors.white,
                padding: EdgeInsets.fromLTRB(30, 5, 30, 5),
                side: BorderSide(width: 0, color: Colors.white),
              ),
              child: Align(
                alignment: Alignment.center,
                child: Text('Dashboard',
                    style: TextStyle(
                        color: Colors.black87,
                        fontSize: 16,
                        fontWeight: FontWeight.normal)),
              ),
              
            ),

可以通过以下两种方式去除ElevatedButton的边框:

方法一:明确设置无边框

在styleFrom中指定side: BorderSide.none,比设置width为0更直观:

ElevatedButton(
  style: ElevatedButton.styleFrom(
    primary: Colors.white,
    padding: EdgeInsets.fromLTRB(30, 5, 30, 5),
    side: BorderSide.none, // 移除边框
    elevation: 0, // 可选:去掉凸起阴影,贴近原FlatButton视觉效果
  ),
  child: Align(
    alignment: Alignment.center,
    child: Text('Dashboard',
        style: TextStyle(
            color: Colors.black87,
            fontSize: 16,
            fontWeight: FontWeight.normal)),
  ),
  onPressed: () {}, // 必须添加,否则按钮会禁用置灰
),

方法二:移除边框配置

ElevatedButton默认没有边框,直接删掉代码中的side参数即可:

ElevatedButton(
  style: ElevatedButton.styleFrom(
    primary: Colors.white,
    padding: EdgeInsets.fromLTRB(30, 5, 30, 5),
    elevation: 0, // 可选:去掉阴影
  ),
  child: Align(
    alignment: Alignment.center,
    child: Text('Dashboard',
        style: TextStyle(
            color: Colors.black87,
            fontSize: 16,
            fontWeight: FontWeight.normal)),
  ),
  onPressed: () {},
),

注意:ElevatedButton必须绑定onPressed回调,否则按钮会处于禁用状态,样式也会受影响。

内容的提问来源于stack exchange,提问作者John Reaper

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 07:03:30