Click here to Skip to main content
15,904,416 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'am using flutter in making my mobile app. I wanted to display specific data from my database in firebase into my app. The problem is that when I run hasData the output says it has no data but I already have some data inputted in my collection in firestore. How do I resolve this?

StreamBuilder<QuerySnapshot>(
                  stream: FirebaseFirestore.instance
                      .collection('customers')
                      .snapshots(),
                  builder: (
                    BuildContext context,
                    AsyncSnapshot<QuerySnapshot> snapshot,
                  ) {
                    if (snapshot.hasData) {
                      var data = 'No Data';
                      return Text(data);
                    }
                    if (snapshot.connectionState == ConnectionState.waiting) {
                      var data = 'Loading';
                      return Text(data);
                    }
                    final data = snapshot.requireData;
                    return ListView.builder(
                        itemCount: data.size,
                        itemBuilder: (context, index) {
                          return Container(
                            child: Column(
                              children: [
                                detailsWidget(
                                  icon: Icons.person,
                                  field: 'Name',
                                  value: '${data.docs[index]['name']}',
                                ),
                                detailsWidget(
                                  icon: Icons.oder,
                                  field: 'Order',
                                  value: '${data.docs[index]['order']}',
                                ),
               
                              ],
                            ),
                          );
                        });
                  }),


What I have tried:

I tried using Document Snapshot but the error always says I have null value or type null is subtype of String
Posted
Comments
Richard MacCutchan 14-Jul-22 4:30am    
At a guess the error message(s) is telling you that you are trying to use an uninitialized reference. But without specific details as to exactly where the error occurs, and its complete text, that remains a guess.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900