DEV Community

Cover image for Flutter Performance Tips (#2): use ListView.builder() for list with a large amount of items
Pedro Massango
Pedro Massango

Posted on

Flutter Performance Tips (#2): use ListView.builder() for list with a large amount of items

We have more than one constructors in the ListView class and sometimes you maybe wondering which one to use in determined case.

ListView(children: [])

This is the default ListView's counstructor that takes a list of Widgets. We must use this in cases where we have a small list views items.

ListView.builder(...)

This is the constructor that we must use for cases that we have a large number of list view items because different than ListView(children: <Widget>[]) this constructor only build items that are visible in the screen. Each time the user scroll the list it build the next visible item.

ListView.separated(...)

This one do the same as the ListView.builder(...) but with a bonus: it takes an separatorBuilder to give us the ability to add a separator between our items.

Top comments (0)