Liv*_*ock 3 dictionary dart firebase flutter google-cloud-firestore
如何返回QuerySnapshot作为Future >>?
程式码片段:
Future <List<Map<dynamic, dynamic>>>() {
List<Map<dynamic,dynamic>> list;
.....
.....
QuerySnapshot collectionSnapshot = await collectionRef.getDocuments();
list = collectionSnapshot.documents; <--- ERROR
return list;
}
Run Code Online (Sandbox Code Playgroud)
我认为我需要使用的Map,但无法绕开它。
collectionSnapshot.documents返回List而不是List类型,您将需要将Documentsnapshots的List转换为List>。我是这样的:
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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4067 次 |
| 最近记录: |