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

解决EventObjects无法赋值给Appointment的List<Object>类型resourceIds参数问题

问题解决:将EventObjects对象传入Appointment的resourceIds参数

错误原因

resourceIds参数的类型是List<Object>?,它要求传入的是Object类型的列表,但你直接传了单个EventObjects对象,类型不匹配,所以触发了类型错误。

正确做法

把单个EventObjects对象放进一个列表里,再传给resourceIds就行。Dart里所有类都默认继承自Object,所以EventObjects实例可以直接放入List<Object>中。

修改后的代码示例

List<Appointment> appointments = <Appointment>[];
appointments.add(Appointment(
  startTime: DateTime.now(),
  endTime: DateTime.now().add(const Duration(hours: 1)),
  subject: 'Formación presencial',
  color: Colors.green,
  notes: "Formación presencial",
  location: "Zaragoza",
  // 将EventObjects对象包裹在列表中传入
  resourceIds: [
    EventObjects(
      profId: "1",
      profAvatar: "as",
      profColor: "dd",
      profNombre: "ee",
      eventoColor: "Cc",
      eventoTipo: "Rr"
    )
  ],
));

补充说明

如果需要传入多个EventObjects对象,直接在列表里添加更多实例即可:

resourceIds: [
  EventObjects(profId: "1", ...),
  EventObjects(profId: "2", ...),
]

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.03 03:21:02