Flutter中RaisedButton未定义错误求助,替换ElevatedButton无效
错误根源
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
相关产品推荐
相关产品推荐

