I have made an expense tracking Flutter application that records expenses and stores them in an SQLite database, displaying them within a ListViewBuilder. However, I have encountered an issue regarding the presentation of transactions. To ensure that the most recent transactions consistently appear at the top, I used the "reverse: true" attribute of listviewbuilder. Unfortunately, this adjustment has caused the transactions to populate from the bottom of the container.
This is the list I am fetching from sqlite:
class txList extends StatelessWidget { final List<Map<String, dynamic>> expenses;
And here I am using listviewbuilder:
child: ListView.builder( reverse: true,
till the length of expenses:
itemCount: expenses.length,
The result I am getting with "reverse: true"
My objective is to have transactions populate from the top of the container, with the most recent entry always displayed at the top and the previous one below.
Same elements order but populating from the top of the container
2
Answers
Reverse is made on the ListBuilder which mean that the widget will be reversed not the list. In order for the list to be reversed, you can maintain a new list in your state and affect it with
var reversedList = yourFisrtList.reversed.toList()
You can try like this
just what you have to do is display your
list items
from thelast index
in thelistViewBuilder