【问题标题】:Flutter list .add function nullFlutter 列表 .add 函数 null
【发布时间】:2020-03-18 06:23:38
【问题描述】:
Future<List<DocumentSnapshot>> finallist() async {
    List<DocumentSnapshot> finallist;

    Future createList(QuerySnapshot snapshot) async {
      List<DocumentSnapshot> listoflocationforsingle = snapshot.documents;
      for (DocumentSnapshot u in listoflocationforsingle) {
        print('Added ' + u.data['country']);
        finallist.add(u);
      }
    }

finallist.add(u) 因 add on null 错误而失败。

Exception has occurred.
NoSuchMethodError (NoSuchMethodError: The method 'add' was called on null.
Receiver: null
Tried calling: add(Instance of 'DocumentSnapshot'))

即使当我将鼠标悬停在 createlist(data) 中的数据上时,它也会显示 QuerySnapshot 列表以及我的 firestore 数据库中的数据。

【问题讨论】:

    标签: android flutter google-cloud-firestore


    【解决方案1】:

    没有一个查询可以从多个子集合中获取数据。 Firestore 查询很浅,一次只能处理单个集合中的文档。如果您想要来自三个子集合的数据,则需要三个查询,每个子集合一个。

    【讨论】:

      【解决方案2】:

      哦,我未来的功能确实做到了。只是我需要添加

      List<DocumentSnapshot> finallist = []; // add in the ' = [] ' 
      

      【讨论】:

        猜你喜欢
        • 2020-04-27
        • 2020-06-28
        • 2021-06-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-09-24
        相关资源
        最近更新 更多