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);
}),
);