I have a dynamic list view, it looks like this:
final items = [...]; // Many items, which can be changed by some conditional.
ListView.builder(
itemCount: items.length,
itemBuilder: (context, index) => SomeWidget(items[index].title)
)
Some conditional (like user text input is changed) will change the items.
After the items change, I will call setState to update the listview.
On the debug environment, it works well. But on the profiler/release mode. The listview easy renders cached.
It looks like this:
When I type query1 -> it will display all items that match with query1.
But after I change to query2 -> SOME TIME, the ListView still keep the render of query1.
BUT, THE MAGIC IS:
- When I log the
buildmethod, I found that the widget is already rebuilt with the new data withquery2. - BUT, the list view still displays the content of
query1. - AFTER I touch on the listview, then move my hand to scroll -> The content of
query2is displayed.
I thought that maybe the ListView should rebuild again. So I try to create a microtask with delay of some seconds and then call setState again. But the ListView still displays the old data.
TLDR;
ListView.builder display cache data. After touching to scroll the listview, the new data is displayed.
- Hard to reproduce on debug mode.
- Easy to reproduce on profile/release mode.
Flutter version: 3.3.0/3.3.1/3.3.2
Theme: useMaterial3 = true/false (tested with both useMaterial3 and non useMaterial3).