Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to give a custom (id || key) for every item in flutter listview?

Tags:

flutter

Is there a way to give custom id to every item in flutter's listview?

I need to update a single item in flutter listview by its id or key.

Why I want to update by Id?

because I want to update a specific item without rebuilding the entire listview items, this may boost performance of my app.

like image 845
Iqbal Jan Avatar asked Dec 08 '22 12:12

Iqbal Jan


1 Answers

I guess you can just use itemBuilder's index since it's not repetitive.

return ListView.builder(
         itemCount: items.length,
         itemBuilder: (context, int index) {
           return ListTile(key: new Key(index.toString()));...
      },
    );
like image 154
westdabestdb Avatar answered Jun 08 '23 02:06

westdabestdb