【问题标题】:Flutter - Class 'QuerySnapshot' has no instance method 'document'Flutter - 类'QuerySnapshot'没有实例方法'document'
【发布时间】:2020-04-11 19:38:31
【问题描述】:

我收到以下错误:

════════ 小部件库捕获的异常 ══════════════════════════════════════════════════ ═════

以下 NoSuchMethodError 被抛出构建 StreamBuilder(脏,状态: _StreamBuilderBaseState>#f469b): 类 'QuerySnapshot' 没有 实例方法“文档”。接收方:“QuerySnapshot”实例 尝试调用:document("+918130343322")

body:
  StreamBuilder(
      stream: Firestore.instance.collection('users').snapshots(),
      builder: (context, snapshot){
        if(!snapshot.hasData) return Text('Loading data.....');
        return
            Center(child: Text(snapshot.data.document(_myMobile)["Name"]),);

_mymobile 是文档 ID。

【问题讨论】:

    标签: flutter snapshot stream-builder


    【解决方案1】:

    此代码为您返回一个列表 snapshot.data.documents 而不是文档

    如果你想这样做,你需要尝试这样做

    final specificDocument = snapshot.data.documents.where((f) {
         return f.documentID == _myMobile;
    }).toList();
    

    【讨论】:

      猜你喜欢
      • 2020-10-21
      • 2020-04-07
      • 1970-01-01
      • 2021-05-04
      • 1970-01-01
      • 2021-04-27
      • 2022-06-15
      • 2021-03-01
      相关资源
      最近更新 更多