As of 2021, there have been some major changes in the cloud_firestore package. I was working with firestore on a project, and found that none of the old tutorials were working due to the API changes.
After going through documentation and a few other answers on Stack, here's the solution for the same.
The first thing that you need to do is create a reference for your collection.
CollectionReference _cat = FirebaseFirestore.instance.collection("categories");
Next step is to query the collection. For this, we will be using the get
method on the collection reference object.
QuerySnapshot querySnapshot = await _cat.get()
Finally, we need to parse the query snapshot to read the data from each document within our collection. Here, we will parse each of the documents as maps (dictionaries) and push them to a list.
final _docData = querySnapshot.docs.map((doc) => doc.data()).toList();
The entire function will look something like this:
getDocumentData () async {
CollectionReference _cat = FirebaseFirestore.instance.collection("categories");
final _docData = querySnapshot.docs.map((doc) => doc.data()).toList();
// do any further processing as you want
}