Search code examples
flutterflutter-listview

what are the differences between ListView.builder and use map function


What are the differences between ListView.builder and the map function when creating list of widgets? and when should we use one over the other?.


Solution

  • if you have a long list of items, use ListView.builder(). it only build items that are visible in the screen. Each time the user scrolls the list it builds the next visible item.

    if you use

    Column(
        children: items.map((items){
            return ...
        }).toList()
    )
    

    it has a heavy build cost.

    so, the best practice in my opinion is that use ListView.builder() . you could use map if you are sure the items are not more than a few items.