deepSortByKey method
Returns new instance of Map, which is recursively sorted by keys. It sorts by keys even Map nested as a value, nested Map inside nested Map and so on.
It does not sort nested List or Set, because keys are sorted by default in those types.
it gets rid of incomparable keys (and associated values) like:
- bool
null
Sort order:
Implementation
Map<K, V> deepSortByKey() => LinkedHashMap.fromIterable(
<dynamic>[...keys.toList(growable: false).deepSort()],
key: (k) => k,
value: (k) {
if (this[k] is Map) {
return (this[k] as Map).deepSortByKey();
} else if (this[k] is Set) {
return _deepSortByKeyInSet(this[k] as Set);
} else if (this[k] is List) {
return _deepSortByKeyInList(this[k] as List);
} else {
return this[k];
}
}).cast<K, V>();