[英]How to read read a value from firebase document field
here is the firebase firestore section这是firebase firestore部分
how do I read the value 'purchase-id'我如何读取值'purchase-id'
this is how I did, but not working这就是我所做的,但没有工作
var collection = FirebaseFirestore.instance.collection('users');
final docSnapshot = await collection.doc('$index').get();
Map<String, dynamic> data = docSnapshot.data()!;
final purID = data['purchased-id'];
the value is receiving but as the future value here is how the value is receiving价值正在接收,但这里的未来价值是价值的接收方式
final purchaseID = coursePurchaseCheck
but this is a Future value, how do I parse that to normal data但这是一个未来值,我如何将其解析为正常数据
how do I properly get document value from firebase??我如何正确地从 firebase 获取文档价值?
Check your index is equal to document key ??检查您的索引是否等于文档键?
You can get document key with below code:您可以使用以下代码获取文档密钥:
List<String> _userKey = [];
await fireStore
.collection('user').get()
.then((QuerySnapshot querySnapshot) {
for (var doc in querySnapshot.docs) {
_userKey.add(doc.id);
}
});
And get data below:并获取以下数据:
for(String _key in _userKey){
await FirebaseFirestore.instance
.collection('user')
.doc(_key)
.get()
.then((DocumentSnapshot documentSnapshot) async {
if (documentSnapshot.exists) {
var data = documentSnapshot.data();
var res = data as Map<String, dynamic>;
final purID = res['purchased-id'];
}
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.