Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly does cacheExtent property in ListView.Builder do?

Tags:

flutter

As title I want to know about cacheExtent and what it's doing. It takes double values; I tried to make it equal to 999999999999999 and then I noticed a huge improvement in ListView.Builder scrolling performance, so I need to know about it.

like image 218
Mohamed Gaber Avatar asked Aug 04 '19 16:08

Mohamed Gaber


People also ask

What does ListView builder do?

ListView. builder is a way of constructing the list where children's (Widgets) are built on demand. However, instead of returning a static widget, it calls a function which can be called multiple times (based on itemCount ) and it's possible to return different widget at each call.

What is the difference between ListView and ListView builder?

In contrast to the default ListView constructor, which requires creating all items at once, the ListView. builder() constructor creates items as they're scrolled onto the screen.


1 Answers

According to the documentation :

cacheExtent is the size of the area that is drawn before being in the visible part of the screen, it has two parts : the one before the visible area where items are already displayed, and the other after the visible area.

When you made the size of cacheExtent very huge (999999999999999) you almost made your ListView draw all its children before and after the currently displayed items, that's way the "lagging" behavior disappeared. But you have to use the cache wisely, because making it very big will result in unpleasant side effects, like significant increase in internet traffic for your users. Lazy loading is there for a reason.

like image 51
Mazin Ibrahim Avatar answered Nov 15 '22 19:11

Mazin Ibrahim