dart - 如何使用 Dart 将文档字段存储在列表中
问题描述
我正在尝试从文档中检索数组字段并将其存储在列表对象中。
这是我到目前为止所尝试的:
List<String> list;
Firestore.instance.collection("ingredients").document("Cutlet").get()
.then((snapshot) => list = snapshot.data["ingredients"]);
debugPrint("list is" + list.toString());
return list;
debugPrint 返回 null。
这是我的firestore的快照。我正在尝试检索成分数组并将其存储在列表中。
解决方案
尝试这个
DocumentSnapshot doc= await Firestore.instance.collection('ingredients').document('cutlet').get();
if(doc.exists) {
var list = doc['ingredients'].map<dynamic>((item) {
return item;
}).toList();
}
推荐阅读
- html - 如何进行 html 图像输入,然后在其上运行 python 算法(对于网站)?
- vue.js - cmd中的vue安装不断向我显示不推荐使用的请求如何修复?
- python - 如何在python中按低于和高于x的值拆分列表
- python - 尝试排序时的无限循环,在 Python 中随机打破关系
- eclipse - Eclipse 快速修复悬停
- php - 从 php 数组中取消设置变量
- image-processing - 给定从图像名称到类标签的映射,如何使用 keras ImageDataGenerator flow_from_directory?
- flutter - 在 AES CTR 模式下,输入数据必须是密码块大小的倍数
- c# - 如何评估 InstanceMethodCallExpressionN
- python - 如何停止在 Python 中裁剪 Tkinter PhotoImage