I want to limit the itemCount
of my ListView
to a maximum of 5 and add the text "and more" if there are more items and only display the items if they are 5 or less. I've tried using itemCount: 5
but that returns an error when the items are less than 5. How can I implement this?
ListView.builder(
shrinkWrap: true,
itemCount: features.length,
itemBuilder: (context, index) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"• ${features[index]}",
style: TextStyle(fontWeight: FontWeight.bold),
overflow: TextOverflow.ellipsis,
),
),
],
);
}),
itemCount: features.length < 5 ? features.length : 5,
Please try this
ListView.builder(
shrinkWrap: true,
itemCount: features.length=>5?5:features.length,
itemBuilder: (context, index) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"• ${features[index]}",
style: TextStyle(fontWeight: FontWeight.bold),
overflow: TextOverflow.ellipsis,
),
),
],
);
}),
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With