Return List of <T> from firestore collections

∥☆過路亽.° 提交于 2020-04-30 05:05:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!