0

I tried printing firebase data using stream, but instead of the data I got this in terminal " [ ] ". This means the data is null. But there is data in firebase, how do I solve this problem.

firebase's data enter image description here enter image description here

stream builder

StreamBuilder(
                stream: FirebaseFirestore.instance
                    .collection('paymentData')
                    .snapshots(),
                builder: (context, AsyncSnapshot<QuerySnapshot> snapshot) {
                  if (!snapshot.hasData) {
                    return const Center(
                      child: Text('Loading'),
                    );
                  }
                  print(snapshot.data!.docs);
                  return ListView(
                      children: snapshot.data!.docs.map((data) {
                    return ListTile(
                      title: Text(data['amount']),
                    );
                  }).toList());
                },
              ),
3
  • can you add your firebase database Commented May 27, 2022 at 12:56
  • Most likely spelling mistake in name of collection. Otherwise the code looks good and would run fine. I would suggest adding a condition to check if the status is loading. Commented May 27, 2022 at 13:07
  • I've shared the screenshots and I think the spelling is right. Commented May 27, 2022 at 13:09

1 Answer 1

1

Based on your firebase structure, there is no path called paymentData, it is actually a nested sub-collection, so in order to reach paymentData, you need to also include the parent of that collection, like this:

stream: FirebaseFirestore.instance
        .collection('lender').doc(yourLenderId).collection('paymentData')
        .snapshots(),

Get the lender ID from a previus step, which is the id of the document

Sign up to request clarification or add additional context in comments.

2 Comments

Instead of yourLenderId will I be able to use name property in paymentData sub-collection as doc?
No, you need to use to use the ID of the document which is inside lender, in your case, it's [email protected].

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.