I am trying to do create a view of ExpansionTile
with ListView.builder
as children. It works well but just if my ListView.builder
become larger, it will need to take some time to render it which slightly affect the user expereince. Is there anyway to help to improve the performance for this?
Below is my sample code:
ExpansionTile(
title: Text(title),
controlAffinity: ListTileControlAffinity.trailing,
initiallyExpanded: true,
maintainState: true,
children: [
ListView.builder(
itemCount: data.length,
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemBuilder: (context, index) => widgetList[index],
)
])
1. shrinkWrap
I would suggest to get rid of shirnkWrap (if possible), as it calculates the size of all elements in the list.
2. ItemBuilder
Also, I recommend to be aware of the operations inside the itemBuilder, because it can slow down rendering the items.