【问题标题】:" the method where isn't defined for the type documentreference"?“没有为类型文档引用定义的方法”?
【发布时间】:2020-10-08 16:23:18
【问题描述】:

为什么我收到此错误“未为类型文档引用定义的方法”? 还有其他过滤文档的方法吗?

 buildPostHeader() {
    return FutureBuilder(
      future:Firestore.instance.collection('users').document(id).where('designer',isEqualTo:true).get(),
      builder: (context, snapshot) {
        if (!snapshot.hasData) {
          return circularProgress();
        }
        User user = User.fromDocument(snapshot.data);
        return Container(
          decoration: BoxDecoration(

              borderRadius: BorderRadius.all(Radius.circular(20.0))
          ),
          margin: EdgeInsets.only(top:10.0,left: 10.0,right: 10.0, bottom: 10.0 ),

          child: Column(
            children:  <Widget> [
              ListTile(
                leading: CircleAvatar(
                  backgroundImage: CachedNetworkImageProvider(user.photoUrl),
                  backgroundColor: Colors.grey,
                ),
                title: Text(user.displayName,style: TextStyle(color: Colors.white),),
                subtitle: GestureDetector(
                  onTap: () => showProfile(context, profileId: user.id),
                  child: Text(
                    user.username,
                    style: TextStyle(
                      color: kText,
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                ),

【问题讨论】:

    标签: firebase flutter dart


    【解决方案1】:

    上述代码的问题 - 您正在指定一个文档 ID,因此您将获得一个文档,并且 where 只能应用于 ListIterable

      Firestore.instance.collection('users').where('designer',isEqualTo:true).getDocuments(),
    

    尝试使用此代码,它将返回一个Future&lt;QuerySnapShot&gt;,而snapshot.data.documents 是一个List&lt;DocumentSnapShot&gt;,如果您想通过 id 或其他方式再次过滤它,您可以使用wheresnapshot.data.documents

    final data = snapshot.data.documents.where(condition);
    

    【讨论】:

      猜你喜欢
      • 2021-09-20
      • 2021-09-02
      • 2021-08-02
      • 2022-11-21
      • 1970-01-01
      • 2021-10-19
      • 2020-12-14
      • 2021-07-19
      • 2021-09-01
      相关资源
      最近更新 更多