latestFirst method

Map<T, T> latestFirst([
  1. String key = 'id'
])

Returns the first item from a list of maps sorted by the given key in descending order.

By default, it sorts by the 'id' key.

Example:

final mostRecentItem = list.latestFirst("timestamp");

Implementation

Map<T, T> latestFirst([String key = 'id']) {
  final List<Map<T, T>> sortedMaps = latest(key);
  return sortedMaps.isNotEmpty ? sortedMaps.first : <T, T>{};
}