skip to Main Content

I am creating an application where I need to have 3 heirarchy for email folders and notes like this: Diagram
Now I’m not able to get the list of documents under the folder collection.

I have tried this till now:

var collection = FirebaseFirestore.instance
    .collection('user')
    .doc(widget.email)
    .collection('folder2');
await collection.get().then((snap) {
  data = snap.size;
  print(data);
});

But this is just giving me 0 in the console, but showing all the entries for the notes collection so what should I do?

2

Answers


  1. Chosen as BEST ANSWER

    So I did get all the documents in the folder level by simply adding a few fields in that Collection like name, description etc. Though I still don't see a way to get all the documents containing subcollections without adding any fields. Newly Created Design


  2. try using the length of the documents retrieved in the result.

    var collection = FirebaseFirestore.instance
        .collection('user')
        .doc(widget.email)
        .collection('folder2');
    await collection.get().then((snap) {
      data = snap.docs.length;
      print(data);
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search