【发布时间】:2021-08-07 03:46:58
【问题描述】:
我将一个列表 (test1) 与另一个列表 (test2) 合并,并获得了动态列表 (marge1),我需要将 marge1 转换为 Map
margeFunction() {
List test1 = [
{
"id": 0,
"name": customerName,
"address": customerAddress,
"mobile": customerMobile,
"deliveryDate": selectedDate1,
},
];
test1.forEach((element) {
test2.forEach((e) {
if (e["id"] == element["id"]) {
marge1.add(getmarge1(
e["id"],
e["itemName"],
e["description"],
e["itemPrice"],
e["image"],
e["unit"],
e["selectedServiceInList"],
e["uniqueListItem"],
e["subTotalListItem"],
e["counter"],
element["name"],
element["address"],
element["mobile"],
element["deliveryDate"],
));
}
});
});
}
Map<String, dynamic> getmarge1(
int id,
String itemName,
String description,
String itemPrice,
String image,
String unit,
String selectedServiceInList,
String uniqueListItem,
int subTotalListItem,
int counter,
String name,
String address,
String mobile,
DateTime deliveryDate) {
final Map<String, dynamic> data = new Map<String, dynamic>();
data["id"] = id;
data["itemName"] = itemName.toString();
data["description"] = description.toString();
data["itemPrice"] = itemPrice.toString();
data["image"] = image.toString();
data["unit"] = unit.toString();
data["selectedServiceInList"] = selectedServiceInList.toString();
data["uniqueListItem"] = uniqueListItem.toString();
data["subTotalListItem"] = subTotalListItem.toString();
data["counter"] = counter.toString();
data["name"] = name.toString();
data["address"] = address.toString();
data["mobile"] = mobile.toString();
data["deliveryDate"] = deliveryDate.toString();
return data;
}
现在我需要将 merge1 列表发送到 firestore。我已经尝试过,但无法弄清楚。任何帮助表示赞赏。
【问题讨论】:
-
你用过
json.encode(YOUR DATA)吗? -
是的,我做到了,但是当我尝试在 setData 上使用它时,它显示 list
,因为它需要 Map 。
标签: flutter google-cloud-firestore