Reverse Iterator for List?

Until the issue #2804 has been fixed, you have to iterate list in reverse order using indices. For your performance concern, it should be good because Lasse R.H. Nielsen once said :

Lists in Dart are intended for random access


You can now reverse the iteration of a list in Dart. Use the reversed getter on List.

var fruits = ['apples', 'oranges', 'pears'];
Iterable inReverse = fruits.reversed;
var fruitsInReverse = inReverse.toList();
print(fruitsInReverse); // [pears, oranges, apples]

You could shorten this to:

var fruits = ['apples', 'oranges', 'pears'];
print(fruits.reversed.toList());

See the API docs.

Tags:

Dart