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

Flutter中RaisedButton未定义错误求助,替换ElevatedButton无效

解决Flutter中RaisedButton未定义的错误

错误根源

RaisedButton在Flutter 2.0版本后已被废弃并移除,官方推荐用ElevatedButton替代。你替换后仍出问题,是因为ElevatedButton的参数结构和RaisedButton不完全一致,直接改名会导致参数不匹配。

正确替换代码

把你的按钮代码改成以下形式,注意参数的调整:

// 带图标的按钮替换为ElevatedButton.icon
ElevatedButton.icon(
  onPressed: () {
    _handleSignIn();
  },
  style: ElevatedButton.styleFrom(
    backgroundColor: Colors.blue, // 替代原color参数
    foregroundColor: Colors.white, // 替代原textColor参数
  ),
  label: Text("Google Giris Yap"),
  icon: Icon(Icons.sentiment_very_satisfied),
),

// 普通按钮替换为ElevatedButton
ElevatedButton(
  onPressed: () {
    SystemChannels.platform.invokeMethod('SystemNavigator.pop');
  },
  style: ElevatedButton.styleFrom(
    backgroundColor: Colors.blue,
    foregroundColor: Colors.white,
  ),
  child: Text("Daha Karpuz Kesecektik :("),
),

关键参数变化说明

  • 原color参数移到style的backgroundColor中
  • 原textColor参数移到style的foregroundColor中
  • ElevatedButton.icon的参数顺序和RaisedButton.icon一致,但样式必须通过style配置

额外检查

确保文件顶部已导入Flutter Material包:

import 'package:flutter/material.dart';

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 02:52:10