dart

Reverse a list in Flutter or Dart

If you want to reverse a list in Dart or Flutter, you can use List.reversed.toList() and it will reorder all the elements of the list in reversed order.

List myList = ['John', 'herry', 'Carl', 'Morgan'];

myList = myList.reversed.toList();

print(myList);

Output

[Morgan, Carl, herry, John]

List.reversed.toList()

The reversed keyword is used to reverse the list and after that, we can use the toList() function to convert the output from List.reverse to a list in Dart.

Another Code Example

List numbers = [10, 20, 30, 40, 50];
  
List result = numbers.reversed.toList();
  
print(result);

Output

[50, 40, 30, 20, 10]
Was this helpful?