< T>的返回列表从消防站收集 [英] Return List of <T> from firestore collections

查看:64
本文介绍了< T>的返回列表从消防站收集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从Firestore集合返回类型T的列表?这是我得到错误的地方,因为返回类型为 List< Map< String,dynamic>>

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;
  }

推荐答案

尝试

final result = data.documents.map<T>((doc) => doc.data as T);

这篇关于&lt; T&gt;的返回列表从消防站收集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆