sorted method

List<T> sorted({
  1. bool isDesc = false,
})

Returns a new sorted list.

If isDesc is true, the list will be sorted in descending order. Otherwise, it will be sorted in ascending order.

Example:

final sortedList = list.sorted(isDesc: true);

Implementation

List<T> sorted({bool isDesc = false}) {
  final List<T> copy = List<T>.of(this);
  copy.sort();
  return isDesc ? copy.reversed.toList() : copy;
}