I want to showing list of items with ListView.builder. My code is success connect to API, but the problem is I do not know how to display the items, instead the length of the items.
Here I attach the code:
child: ListView.builder(
itemCount: state.Food.length,
itemBuilder: (context, index) {
return Row(
children: [
const SizedBox(
height: 10,
width: 10,
child: CircleAvatar(
foregroundColor:
ColorName.brandSecondaryGreen,
backgroundColor:
ColorName.brandSecondaryGreen,
),
),
const SizedBox(
width: 5,
),
Text(
state.Food.length.toString(), //The problem is here----------
style: subtitle1(),
),
],
);
},
);
},
),
),
),
2
Answers
Instead of this
use the index of the list builder
As you are iterating over the Listview, it gives you
index
to access the property of the individual iterated item , usingindex
you can display the item.Example: