How to reverse listview in Flutter
You should be able to reverse the list before feeding it to the ListView
.
List<String> animals = ['cat', 'dog', 'duck'];
List<String> reversedAnimals = animals.reversed.toList();
Here is a solution with null safety support of reverse the listview. Do not use reverse:true because it will reverse your data but when you open listview.builder widget in your app it will take automatically to scroll to the last item. To avoid that use this:-
ListView.builder(
itemCount: customer?.data.length ?? 0,
itemBuilder: (BuildContext context, int index) {
int itemCount = customer?.data.length ?? 0;
int reversedIndex = itemCount - 1 - index;
child: Container(
child: Text(value.allCustomerModel!.data![reversedIndex].attributes!.name.toString(),
),)
In ListView has an attitude is reverse, set it is true to reverse your list:
ListView.builder(
reverse: true,
);
For ListView
there is a flag called reverse
which is false by default. Change it to true