Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter reversed ListView start at top

I have a ListView which normally starts at the top and can be scrolled down, but I have reverse set to true which is what I need it to be, but now the list starts from the bottom.

How can I set the start position so it starts at the top and scrolls down despite being reversed?

So basically it's like this, with the date order reversed like I need:

14th
12th
7th
6th
5th

But the whole thing is scrolled to the bottom by default...so I can't see 12th and 14th unless I scroll up.

....off the top of the screen
7th
6th
5th
4th
3rd - starting position.

I need it to start from the scrolled to the top by setting the scroll start position. I hope this description makes it a bit clearer.

like image 769
Hasen Avatar asked Dec 23 '22 21:12

Hasen


1 Answers

You can reverse the order of presentation in this manner as well: Note the ((feed.length-1) - index) array index. Using some combination of this technique and what you are using will result in what you desire.

List<String> feed = List();

feed.add("AAAA");
feed.add("BBBB");
feed.add("CCCC");

ListView.builder(
  itemCount: feed.length,
  itemBuilder: (context, index) {
    return ListTile(title: feed[(feed.length - 1) - index]);
  },
);
like image 80
E.Bradford Avatar answered Jan 29 '23 06:01

E.Bradford