![](/img/trans.png)
[英]Flutter: Bad state: field does not exist within the DocumentSnapshotPlatform | cloudfirestore
[英]Exception has occurred. StateError (Bad state: field does not exist within the DocumentSnapshotPlatform) - When I make a request Flutter Firestore
我需要从 Firestore 中的数组获取数据。
我收到一个错误:
StateError (Bad state: field does not exist within the DocumentSnapshotPlatform)
当我在 firestore 数据库上运行以下查询时:
Future getData() async {
await FirebaseFirestore.instance
.collection("users")
.get()
.then((QuerySnapshot? querySnapshot) {
querySnapshot!.docs.forEach((doc) {
alldata = doc["errors"];
});
});
}
我如何正确地进行此查询?
试试这个:
Future getData() async {
final snapshot = await FirebaseFirestore.instance
.collection("users")
.get();
querySnapshot!.docs.forEach((doc) {
alldata = (doc.data() as Map<String, dynamic>)["errors"];
});
}
解决了!
Future getData() async {
final docRef =
await FirebaseFirestore.instance.collection("users").doc(user.uid);
docRef.get().then(
(DocumentSnapshot doc) {
alldata = (doc.data() as Map<String, dynamic>)["errors"];
print('Получен массив данных: ${alldata}');
print('Получен массив данных: ${alldata.first}');
},
onError: (e) => print("Error getting document: $e"),
);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.