latestFirst method

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

The latestFirst methods allow you to easily order results by id in descending order and get first record. By default, the result will be ordered by the id field. Or, you may pass the key that you wish to sort by:

Example:

list.latestFirst()

Implementation

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