updateKeys method
Returns a new map with updated keys based on the provided transformation function.
If the map is null
or empty, it returns an empty map {}
.
Example:
final map = {'framework': "Flutter", 'language': "Dart"};
final newMap = map.updateKeys((key) => "$key's");
print(newMap);
Output:
{framework's: Flutter, language's: Dart}
Implementation
Map<String, V> updateKeys(String Function(String key) newKey) {
if (isNullOrEmpty) return {};
final map = <String, V>{};
for (var key in this!.keys) {
map.addAll({newKey.call(key): this?[key] as V});
// map[key] = this?[key] as V;
}
return map;
}