sortBy static method

List sortBy(
  1. List list,
  2. String key, [
  3. bool isDesc = false
])

The sortBy method sorts the list of objects by the given key.

Example:

sortBy(list, "price") // create new list with soreted list according to price

Implementation

static List<dynamic> sortBy(List<dynamic> list, String key,
    [bool isDesc = false]) {
  list.sort((dynamic a, dynamic b) => a[key].compareTo(b[key]));

  return isDesc ? list.reversed.toList() : list;
}