sortedByTime method

List<T> sortedByTime(
  1. Comparable key(
    1. T e
    ), {
  2. bool reversed = false,
})

Implementation

List<T> sortedByTime(Comparable key(T e), {bool reversed = false}) {
  // Sort with a custom comparison to handle "Anytime" items first
  List<T> sortedList = List<T>.from(this)
    ..sort((a, b) {
      final valueA = key(a);
      final valueB = key(b);

      // Check if either value is "Anytime", push those to the top
      if (valueA == 'Anytime') return 1;
      if (valueB == 'Anytime') return -1;

      // Otherwise, compare normally
      return valueA.compareTo(valueB);
    });

  // Reverse if needed
  return reversed ? sortedList.reversed.toList() : sortedList;
}