I'm trying to build a ListView with ListTile
Code here :
List<bool> isRed2 = [
true,true,false,false,
true,true,true,false,
false,false,true,true,
false,true,true,true,
true,];
return ListView.builder(
padding: EdgeInsets.all(0),
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: isRed2.length,
itemBuilder: (context, i) => ListTile(
dense: true,
minVerticalPadding: 0,
contentPadding: EdgeInsets.all(0),
minLeadingWidth: 0,
horizontalTitleGap: 0,
title: isRed2[i]
? Container(
height: 50,
color: Colors.red,
)
: Container(
height: 1,
color: Colors.blue,
)));
I set those elements which value is false height = 1 but they still have lots of space.
Any idea how to set height to match widget or skip those value is false?
Problems:
- Can't add Container or SizedBox "outside" ListTile, it will slow down when showing long list.
- ListTile is needed for showing then faster, adding widgets without ListTile will slow down.
- Copy elements which value is "true" to new list and build by it is not a good idea for my situation.
Try to set
visualDensity
read more aboutListTile