How to reverse listview in Flutter
33,966
Solution 1
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();
Solution 2
For ListView
there is a flag called reverse
which is false by default. Change it to true
Solution 3
In ListView has an attitude is reverse, set it is true to reverse your list:
ListView.builder(
reverse: true,
);
Solution 4
Instead of reversing listview
, get your list reversed using reversed property or reverse function.
Solution 5
just set reverse: true
return MaterialApp(
home: Scaffold(
appBar: appBar(),
body: ListView.builder(
shrinkWrap: true,
reverse: true, // here
itemCount: 5,
itemBuilder: (context, index){
return listDesign(index);
},
),
),
);
Author by
Dev9977
Updated on February 02, 2022Comments
-
Dev9977 over 2 years
I implemented a
listview
which get data from ajson
.I followed this implementation.
How could i reverse the order of this listview? (The first element should became the last, ecc...).
-
Maulik over 4 yearsNo. at some point your list is not reverse by using reverse : true. It started pointing your all list from bottom of Listview. So better is to reverse your array.
-
ᴅ ᴇ ʙ ᴊ ᴇᴇ ᴛ about 2 yearsThis reverse:true takes to the last element of the list when clicked, so this is not the perfect solution.