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

Flutter中已弃用的RaisedButton如何替换为ElevatedButton实现相同效果

等效实现代码

ElevatedButton(
  onPressed: null,
  style: ElevatedButton.styleFrom(
    shape: RoundedRectangleBorder(
      borderRadius: BorderRadius.circular(24.0),
    ),
    padding: EdgeInsets.all(12.0),
    backgroundColor: Colors.blue,
    foregroundColor: Colors.white,
  ),
  child: Text("Button"),
)

配置说明

  • ElevatedButton的所有样式属性统一通过style参数配置,使用官方提供的ElevatedButton.styleFrom静态方法可以快速完成常用样式设置,不需要自定义Style类。
  • 原RaisedButton的shape、padding属性直接迁移到styleFrom方法内即可。
  • 原color属性对应styleFrom内的backgroundColor参数,原Text组件中设置的白色文字样式,可以直接通过foregroundColor参数统一配置,无需单独给Text组件设置样式,效果完全一致。
  • onPressed参数逻辑和旧版RaisedButton完全一致,传null时按钮为禁用状态,表现无差异。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.03 06:27:04