【发布时间】:2021-06-17 20:58:02
【问题描述】:
我有这个自定义对象,我想将其写入 Firestore,但出现此错误:
未处理的异常:无效参数:“CheckboxModel”实例
我的两个班级:
class TaskModel {
String taskId;
String taskTitle;
String taskColor;
DateTime taskDateEdit;
List<CheckboxModel> checkboxItems;
}
class CheckboxModel{
String checkboxContent;
bool isDone;
}
这是写入firestore的方法:
void addTask(TaskModel task){
String _uid = _firebaseService.auth.currentUser.uid;
_firebaseService.firestore
.collection("users")
.doc(_uid)
.collection("tasks")
.doc(task.taskId)
.set(task.toMap());
}
关于我应该如何处理这个问题的任何帮助建议?提前致谢!
【问题讨论】:
-
您已经有一个
task.toMap()呼叫。您能展示一下您是如何实现toMap函数的吗? -
@FrankvanPuffelen 这是我的 TaskModel 类中的 'toMap()' 方法:
Map<String, dynamic> toMap() => { "task_id": taskId == null ? null : taskId, "task_title": taskTitle == null ? null : taskTitle, "task_color": taskColor == null ? null : taskColor, "task_date_edit": taskDateEdit == null ? null : taskDateEdit.toIso8601String(), "task_items": checkboxItems == null ? null : List<dynamic>.from(checkboxItems.map((x) => x)), };我使用了 this generator -
很高兴在下面看到您找到了解决方案。将来,请在问题中添加澄清代码而不是在评论中,因为否则很难解析。
标签: firebase flutter dart google-cloud-firestore