Flutter Convert from QuerySnapshot to a Future <List<Map<dynamic, dynamic>>>
14,637
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;
}
Author by
LiveRock
Updated on December 05, 2022Comments
-
LiveRock over 1 year
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.