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

Flutter中RaisedButton替换为ElevatedButton的样式适配求助

RaisedButton 转 ElevatedButton 正确转换方案

直接上转换后的完整代码:

Padding(
  padding: const EdgeInsets.symmetric(horizontal: 40.0),
  child: ElevatedButton(
    child: Text(
      "Gruppen Id kopieren",
      style: TextStyle(
        color: Colors.white,
      ),
    ),
    onPressed: () => _copyGroupId(context),
    style: ButtonStyle(
      // 对应原RaisedButton的color属性
      backgroundColor: MaterialStateProperty.all(Color.fromRGBO(245, 168, 0, 1)),
      // 对应原RaisedButton的shape属性
      shape: MaterialStateProperty.all(RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(20.0),
        side: BorderSide(
          color: Theme.of(context).secondaryHeaderColor,
          width: 2,
        ),
      )),
    ),
  ),
),

关键属性映射说明:

  • 原RaisedButton的color:需要放到ButtonStyle的backgroundColor中,用MaterialStateProperty.all()包裹颜色值——ElevatedButton的样式属性支持区分不同状态(如按下、禁用)的样式,若不需要区分状态,用all()设置固定值即可。
  • 原RaisedButton的shape:直接移到ButtonStyle的shape字段,同样用MaterialStateProperty.all()包裹原有RoundedRectangleBorder配置。
  • child、onPressed这类属性用法和原代码完全一致,无需修改。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.20 07:30:48