"метод где не определен для типа documentreference"? - PullRequest
0 голосов
/ 18 июня 2020

, почему я получаю эту ошибку «метод, в котором не определен для типа documentreference»? есть ли другой способ фильтровать документы?

 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,
                    ),
                  ),
                ),

1 Ответ

0 голосов
/ 19 июня 2020

Проблема с приведенным выше кодом - вы указываете идентификатор документа, чтобы получить один документ, а where можно применить только к List или Iterable

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

Попробуйте использовать это code, он вернет Future<QuerySnapShot>, а snapshot.data.documents - это List<DocumentSnapShot>, который передал условие where, если вы хотите снова отфильтровать его по идентификатору или чему-то еще, вы можете сделать это, используя where to snapshot.data.documents

final data = snapshot.data.documents.where(condition);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...