renameKey method

Map<K, V> renameKey(
  1. K from,
  2. K to
)

Returns a new map with the key from renamed to to.

{'old': 1}.renameKey('old', 'new') // {'new': 1}

Implementation

Map<K, V> renameKey(K from, K to) {
  if (!containsKey(from)) return Map.from(this);
  final result = Map<K, V>.from(this);
  result[to] = result.remove(from) as V;
  return result;
}