Issue
enter image description hereenter image description here
I develop an application by using Flutter and firestore. But now I having trouble, I don't know how to get the field value(underlined in red),I have read the Firebase Documentation but it's still confused me.
My English is pretty limited,please forgive me.
Solution
With Firestore, you first read the entire document, and then get the fields you want on the client (in this case Flutter).
For example:
FirebaseFirestore.instance
.collection('playroom')
.get()
.then((QuerySnapshot querySnapshot) {
querySnapshot.docs.forEach((doc) {
print(doc["Material_List"][0]["X1"]);
});
});
This prints all of the first "X1" values in the playroom collection.
If you want a specific document, do this:
FirebaseFirestore.instance
.collection('playroom')
.doc("ID OF THE DOCUMENT")
.get()
.then((DocumentSnapshot doc) {
print(doc.data()["Material_List"][0]["X1"]);
});
Answered By - Connor W
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.