How do I return a QuerySnapshot as a Future >> ?
Code snippet:
Future <List<Map<dynamic, dynamic>>>() {
List<Map<dynamic,dynamic>> list;
.....
.....
QuerySnapshot collectionSnapshot = await collectionRef.getDocuments();
list = collectionSnapshot.documents; <--- ERROR
return list;
}
I think I need to use a Map of but couldn't get around it to work.
collectionSnapshot.documents return List and not List types, you will need to convert List of documentsnapshots to List<Map<dynamic, dynamic>>
.
My be something like this:
Future <List<Map<dynamic, dynamic>>> getCollection() async{
List<DocumentSnapshot> templist;
List<Map<dynamic, dynamic>> list = new List();
CollectionReference collectionRef = Firestore.instance.collection("path");
QuerySnapshot collectionSnapshot = await collectionRef.getDocuments();
templist = collectionSnapshot.documents; // <--- ERROR
list = templist.map((DocumentSnapshot docSnapshot){
return docSnapshot.data;
}).toList();
return list;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With