skip to Main Content

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,

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

2

Answers


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

    Login or Signup to reply.
  2. You can try like this

    just what you have to do is display your list items from the last index in the listViewBuilder

        List<int> numberList = List.generate(10,(index)=> index);
    
        ListView.builder(
          itemCount: numberList.length,
          itemBuilder: (context,index){
            return ListTile(
              title: Text(numberList[numberList.length-1-index].toString()),
            );
          },
        ),
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search