Is there a reverse
option for a SliverList
like there is for ListView.builder
?
I can see that the CustomScrollView
has a reverse
method but that doesn't help for what I'm looking for.
Since SliverList
does not have a a reverse
option or parameter, you'll have to calculate the reversed index by hand inside the SliverChildDelegate
that's used to create the children. This would only be possible if you know the length of the list you are building.
Given you have a List
, you can calculate the reversed index from SliverChildDelegate.builder
's index.
(BuildContext context, int index) {
final reversedIndex = items.length - index - 1;
...
}
Here is what it looks with a SliverChildBuilderDelegate
:
SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
final reversedIndex = items.length - index - 1;
return MyWidget(items[reversedIndex]);
},
childCount: items.length,
),
);
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