如何为具有自定义类对象列表的 Firestore 创建映射<字符串、动态>?



我正在尝试使用firestore为我的应用程序添加持久性。这似乎是王牌,但我在路上遇到了一个颠簸,谷歌搜索似乎让我失望了。我认为这可能更像是一个飞镖问题而不是火店,所以请根据需要进行编辑!

本质上,我的情况类似于以下内容:

class attributes(){
double xpos, ypos;
String id;
}
class item(){
String name;
int price;
List<attributes> attributeHistory;
Map<String, dynamic> toMap(){
Map<String, dynamic> returnMap = new Map();
returnMap['name'] = name;
returnMap['price'] = price;
returnMap['attributeHistory'] = //what goes here??;
}
}

所以。。。那里有什么?我已经为属性编写了一个 .toMap 函数,但我不知道它会让我从哪里得到!

有什么想法吗?

创建Map<String,dynamic>List

returnMap['attributeHistory'] = attributeHistory.map((attribute) {
Map<String,dynamic> attributeMap = new Map<String,dynamic>();
attributeMap["id"] = attribute.id;
// same for xpos and ypos
return attributeMap;
}).toList();

最新更新