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?
Similar Posts
- Check if list is empty in Flutter/Dart
- Sort a list in ascending and descending order Dart or Flutter
- Remove empty and falsey values from a List in Dart/Flutter
- Delete item from a List in Flutter [Dart]
- Loop through a List in Flutter [Dart]
- Check if a String is empty or null in Dart / Flutter
- Foreach Loop in Flutter [Dart]