如何去除Flutter中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
相关产品推荐
相关产品推荐

