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);
      },
    ),
  ),
);
Share:
33,966
Dev9977
Author by

Dev9977

Updated on February 02, 2022

Comments

  • Dev9977
    Dev9977 over 2 years

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

  • Maulik
    Maulik over 4 years
    No. 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 years
    This reverse:true takes to the last element of the list when clicked, so this is not the perfect solution.