Reputation: 21
How do I loop through a DocumentSnapshot.data() object and retrieve its keys and values? My code currently looks like this:
Future<void> drawPolygons() async {
var points = await FirebaseFirestore.instance
.collection('polygons')
.doc(uid)
.get()
.then((DocumentSnapshot documentSnapshot) {
if (documentSnapshot.exists) {
//if user has polygon data on account
var data = documentSnapshot.data();
}
});
}
Upvotes: 0
Views: 198
Reputation: 1242
**Update Your Method and Convert the data to Map**
Future<void> drawPolygons() async {
var points = await FirebaseFirestore.instance
.collection('polygons')
.doc(uid)
.get()
.then((DocumentSnapshot documentSnapshot) {
if (documentSnapshot.exists) {
Map data = (documentSnapshot.data() as Map);
for (var entry in data.values) {
print(entry);
}
}
});
}
Upvotes: 2