How to make list view to listview.builder in flutter?
467
You should do the following:
if (snapshot.connectionState == ConnectionState.done) {
return ListView.builder(
shrinkWrap: true,
itemCount: snapshot.data.documents.length,
itemBuilder: (BuildContext context, int index) {
return ListTile(
contentPadding: EdgeInsets.all(8.0),
title: Text(snapshot.data.documents[index].data["name"]),
);
});
Assuming you have name
in the document.
Author by
Rishabh Shukla
Updated on December 21, 2022Comments
-
Rishabh Shukla over 1 year
buildComments() { return StreamBuilder( stream: commentRef .document(postId) .collection('comments') .orderBy('timestamp', descending: false) .snapshots(), builder: (context, snapshot) { if (!snapshot.hasData) { return circularProgress(); } List<Comment> comments = []; snapshot.data.documents.forEach((doc) { print(comments); comments.add(Comment.fromDocument(doc)); }); return ListView( children: comments, ); }); }
I was trying to convert it in list view.builder but it gives me error you can can't use list instead of Widget, Can anyone solve this problem.