I implemented a listview
which get data from a json
.
I followed this implementation.
How could i reverse the order of this listview? (The first element should became the last, ecc...).
ListView is a very important widget in a flutter. It is used to create the list of children But when we want to create a list recursively without writing code again and again then ListView. builder is used instead of ListView.
We can reverse a List in Dart either by using built-in functions or using looping statements with swap mechanism. Reversing a List makes the first element to be placed at last position, second element placed at last but one position and so on.
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();
For ListView
there is a flag called reverse
which is false by default. Change it to true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With