问题
How can I return a List of type T from firestore collections? Here is where I get which result in an error because the return type is of type List<Map<String, dynamic>>
Future<List<T>> getCollections<T>(String path) async {
final data = await Firestore.instance.collection(path).getDocuments();
final result = data.documents.map((doc) => doc.data).toList();
return result;
}
回答1:
try
final result = data.documents.map<T>((doc) => doc.data as T);
来源:https://stackoverflow.com/questions/61287187/return-list-of-t-from-firestore-collections