简体   繁体   中英

The getter 'documents' isn't defined for the type 'QuerySnapshot<Object?>'

var capitalValue = value.substring(0,1).toUpperCase() + value.substring(1);

    if(queryResult.length == 0 && value.length == 1) {
       SearchService().searchProduct(value).then((QuerySnapshot docs){
         for(int i = 0; i < docs.documents//here error .length; i++) {
           queryResult.add(docs.documents//here error [i].data);
         }
       });
    }
    else{
      tempSearch = [];
      queryResult.forEach((element) {
        if(element['category'].startsWith(capitalValue)) {
          setState(() {
            tempSearch.add(element); 
          });
        }
      });
    }
  }

The getter 'documents' isn't defined for the type 'QuerySnapshot<Object?>'.Currently, I'm coding to make a search in the application

I think you are following some old documentation or tutorial. As far as I remember, object of QuerySnapshot has been changed few months ago.

They have simplified the usage by changing documents to docs and document to doc.

So your code should be like this

SearchService().searchProduct(value).then((QuerySnapshot docs){
   for(int i = 0; i < docs.docs.length; i++) {
      queryResult.add(docs.docs[i].data);
   }
});

You can review the changelog here https://gist.github.com/Salakar/a36bd0902d7d0c705696da9318cf4e71

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM