dart - 无法将参数类型“”分配给参数类型 List <>
问题描述
我正在尝试从函数中获取学生列表seasonalStudents
并将其用于另一个函数studentListener
我想使用unHapyyStd
,但在这一行unHappyStd = [StaticStudents(std.id, null, TotalStudents(std.id, null))];
出现错误The argument type TotalStudents can't be assigned to the parameter Type List<TotalStudents>
,我该如何解决?
class Toppers {
String id;
double passmark;
double failmark;
Toppers(this.id, this.passmark, this.failmark);
}
class TotalStudents {
final String id;
final Image markerIcon;
TotalStudents(
this.id,
this.markerIcon,
);
}
class StaticStudents {
final String id;
final String call;
final List<TotalStudents> totalStds;
StaticStudents(this.id, this.call, this.totalStds);
}
class Students {}
class NearPassedStudents {
String id;
double passmark;
double failmark;
NearPassedStudents(this.id, this.passmark, this.failmark);
}
class GeoStudents {
static List<NearPassedStudents> passedStudentsList = [];
}
void seasonalStudents() {
for (NearPassedStudents std in GeoStudents.passedStudentsList) {
print("student: ${std.id}");
print("student: ${std.passmark}");
print("student: ${std.failmark}");
unHappyStd = [StaticStudents(std.id, null, TotalStudents(std.id, std.passmark))];
}
Future<void> studentListener()async{
////some method
/// use it here
case studentX:
seasonalStudents();
}
}
解决方案
您的问题是StaticStudents
构造函数中的第三个参数需要该类型List<TotalStudents>
,但您将TotalStudents
对象作为参数发送:
StaticStudents(std.id, null, TotalStudents(std.id, null))
相反,List
如果您只想使用一个列表,TotalStudents
请使用以下内容:
StaticStudents(std.id, null, [TotalStudents(std.id, null)])
推荐阅读
- javascript - HTML - 悬停时显示图像
- javascript - 如何通过 Crypto-JS 解密 AES 128-CBC?
- f# - 无法使用 F# 和 RestSharp for Mailgun 对 REST Api 进行身份验证
- python - 如何在CSV文件中转换python字典文件(具有二维数组)
- visual-studio - 有没有办法在 Visual Studio 中更改参考提示的字体?
- javascript - 如何在 React 17 中不启动 ComponentDidMount() 方法
- python - Elast 警报 email_from_field 仅向一个收件人发送消息
- php - AWS SES 电子邮件发送错误:无法连接到 SMTP 主机
- java - List 时返回 null