Home > front end >  how to add extra list in list view.builder in flutter
how to add extra list in list view.builder in flutter

Time:10-13

I want to add an extra list that shows total of entries in listview.builder

here is my code but not working as index not possible to length

return Scaffold(
      appBar: AppBar(title: Text('Exp Entries'),),
      body: ListView.builder(
          itemCount: noteprovider.expenseentries.length,
          itemBuilder: (context,index){

            if(index==noteprovider.expenseentries.length)
              return Text(noteprovider.expense_total.toString());
            else
             return Text(noteprovider.expenseentries[index].title);

          }),
    );

CodePudding user response:

You must add 1 to length on itemCount :

return Scaffold(
      appBar: AppBar(title: Text('Exp Entries'),),
      body: ListView.builder(
          itemCount: noteprovider.expenseentries.length   1,
          itemBuilder: (context,index){

            if(index==noteprovider.expenseentries.length)
              return Text(noteprovider.expense_total.toString());
            else
             return Text(noteprovider.expenseentries[index].title);

          }),
    );
  • Related