Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I display the latest list item at the top of list in listviewbuilder (Flutter)?

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;

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

And here I am using listviewbuilder:

child: ListView.builder( reverse: true,

till the length of expenses:

itemCount: expenses.length,

Without reverse

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

>Solution :

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()

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading