I was looking at this example in google codelabs. https://codelabs.developers.google.com/codelabs/flutter-firebase/#10
In it, there is this particular listview with the following code:
Widget _buildList(BuildContext context, List<DocumentSnapshot> snapshot) {
return ListView(
padding: const EdgeInsets.only(top: 20.0),
children: snapshot.map((data) => _buildListItem(context, data)).toList(),
);
}
I am interested to convert the Listview to using Listview.builder but somehow I could not figure out how I could do it. Any hint or help would be greatly appreciated.
Widget _buildList(BuildContext context, List<DocumentSnapshot> snapshot) {
return ListView.builder(
itemBuilder: (ctx, index) {
return _buildListItem(context,snapshot[index]);
}
itemCount: snapshot.length,
padding: const EdgeInsets.only(top: 20.0),
);
}
This should do the job.
You could try this:
Widget _buildList(BuildContext context, List<DocumentSnapshot> snapshot) {
return ListView.builder(
padding: const EdgeInsets.only(top: 20.0),
itemCount: snapshot.length,
itemBuilder: (context, index) {
return _buildListItem(context, snapshot[index]);
}
);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.