How to reverse a List in Flutter

October 10, 2022 No comments flutter dart reverse list

Introduction

In Flutter/Dart, we may need to reverse a List. We'll examine how to do it in this tutorial.

How to reverse a List in Flutter

To reverse a list in Flutter/Dart we can use the reverse property available in the List class:

var list = ['one', 'two', 'three'];
var reversedList = List.of(list.reversed); // creates new list with reversed items

print(reversedList);

The output:

['three', 'two', 'one']

Conclusion

In this article, we presented how to reverse a list in Flutter. Luckily lists in Flutter have dedicated property that returns reverse items, so we don't need to create complicated code to do it.

{{ message }}

{{ 'Comments are closed.' | trans }}