【发布时间】:2021-03-20 14:44:58
【问题描述】:
我正在尝试从我的集合中检索一组数据,但每次运行代码时都会出错:
“未处理的异常:错误状态:DocumentSnapshotPlatform 中不存在字段”,并且从 Firestore 中没有检索到任何内容。
代码如下:
class EnterRefferal extends StatefulWidget {
@override
_EnterRefferalState createState() => _EnterRefferalState();
}
class _EnterRefferalState extends State<EnterRefferal> {
List<String> refId = [];
void initState() {
super.initState();
FirebaseFirestore.instance
.collection("clients")
.get()
.then((QuerySnapshot querySnapshot) => {
setState(() {
querySnapshot.docs.forEach((doc) {
refId.addAll([doc["refID"]]);
});
}),
});
}
@override
Widget build(BuildContext context) {
print(refId);
请帮我解决这个问题,在此先感谢。
【问题讨论】:
-
您的收藏在 Firestore 中是什么样的?
-
错误消息表明您的
clients集合中没有名为refID的字段。您能否分享您的 Firestore 结构,以便我们检查您要获取的内容?
标签: flutter google-cloud-firestore