How to get Firebase snapshots length?
1,960
Try to explicitly declare type in your StreamBuilder
StreamBuilder<QuerySnapshot>(
stream: _firestore.collection('...').snapshots(),
https://dart.dev/guides/language/sound-problems#runtime-errors
Author by
dfdfdsfsd
Updated on December 15, 2022Comments
-
dfdfdsfsd over 1 year
I've created an app with Firebase but I've got a problem, which is that I
can't count the snapshot length in listview.builder.
StreamBuilder( stream: _firestore.collection('/posts/${widget.uid}/comments').snapshots(), builder: (context, snapshot) { final data = snapshot.data.documents; if (!snapshot.hasData) { return SpinKitChasingDots( color: Colors.lightGreen, ); } return ListView.builder( itemCount: snapshot.data.documents.length,//Here is the problem itemBuilder: (context, index) { return PostComment( commentText: data[index]['commentText'], userImage: data[index]['userImage'], userName: data[index]['userName'], ); }, ); }, ),
When I run it gives me an error that it doesn't have actually a getter called length.
-
dfdfdsfsd over 4 yearseverything is going okay except displaying it as I've mentioned above
-
Dennis Alund over 4 yearsCan you confirm that you tried the answer and it didn't help?
-
dfdfdsfsd over 4 yearsI've not noticed your data type declaring and it worked, thanks
-
Community over 1 yearYour answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.