support@codebucket.net

What is Flutter Listview builder?

What is Flutter Listview builder?

Nafis Hasrat Arnob | December 19, 2022

Hello developers,

 

Sometimes we want to show our data in the flutter app. In this demonstration, I will show how you can work with the listview builder in flutter. Let's find out.

 

In the app, we show a lot of data in the list. To show a list we can use a lot of widgets. But one of the most used widgets is ListView. If we want to create a list recursively we can use ListView.builder. ListView.builder creates a scrollable linear array of widgets.

 

Constructors of ListView.builder are as follows:

 

ListView.builder({
Key key, 
Axis scrollDirection, 
bool reverse, 
ScrollController controller, 
bool primary, 
ScrollPhysics physics, 
bool shrinkWrap, 
EdgeInsetsGeometry padding, 
double itemExtent, 
Widget Function(BuildContext, int) itemBuilder, 
int itemCount, 
bool addAutomaticKeepAlives, 
bool addRepaintBoundaries, 
bool addSemanticIndexes, 
double cacheExtent, 
int semanticChildCount, 
DragStartBehavior dragStartBehavior})

 

First, we need to put the data in a list. Then we need to mention the length of list in itemCount. We also can declare scrollDirection, padding, shrinkWrap etc. Then we need to declear itemBuilder. In the itemBuilder function, we need to return a widget to show the items on the list.

 

Here is an example of ListView.builder below:

 

ListView.builder(
  itemCount: data.length,
    scrollDirection: Axis.vertical,
    padding: const EdgeInsets.all(20),
    shrinkWrap: true,
    itemBuilder: (context, index) {
    return ListTile(
      leading: const Icon(Icons.list),
      title: Text(data[index]),
      subtitle: Text(index.toString()),
      onTap: () {
        
      },
    );
    }
),

 

Hope this might help you in your journey of development.

 

Read More: Know about the Flutter Column and Row

Nafis Hasrat Arnob

Nafis Hasrat Arnob

Information Analyst

I am a Flutter developer working for a reputed company in Bangladesh. I am trying my best to gain proficiency in Software Development. I am also interested in Artificial Intelligence, Machine Learning, and Computer Vision.