'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.
Solution 1:[1]
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]);
},
);
Solution 2:[2]
After placing data in list,just use reversed property of iterable(list).
List<int> i = List();
i.add(3);
i.add(5);
i.add(8);
for (int j in i.reversed) {
print('$j');
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Handsome Devil |
