sortMapEntries<K, V> function
Map<K, V>
sortMapEntries<K, V>(
- Map<
K, V> map, [ - CompareMapEntryFunction<
K, V> ? compare, - bool reversed = false
Returns a Map with sorted entries.
Implementation
Map<K, V> sortMapEntries<K, V>(Map<K, V> map,
[CompareMapEntryFunction<K, V>? compare, bool reversed = false]) {
compare ??= (a, b) => parseComparable(a.key)!.compareTo(b.key);
if (reversed) {
var compareOriginal = compare;
compare = (a, b) => compareOriginal(b, a);
}
var mapSorted =
LinkedHashMap<K, V>.fromEntries(map.entries.toList()..sort(compare));
return mapSorted;
}