removeFromMap function
Removes a key from a map with the depth definded by List<String> keyPath
Implementation
void removeFromMap(Map<String, dynamic> map, List<String> keyPath) {
// not valid
if (keyPath.isEmpty) return;
// toplevel key
if (keyPath.length == 1) {
map.remove(keyPath.last);
return;
}
// nested keys
if (keyPath.length == 2) {
map[keyPath[keyPath.length - 2]].remove(keyPath.last);
_removeEmptyness(map, keyPath.sublist(0, keyPath.length - 1));
} else {
removeFromMap(map[keyPath.removeAt(0)], keyPath);
}
}