What is the Map.map() method in Dart?

The Map.map() method can be used to create a new map with all entries modified or transformed.

Syntax

map_name.map((k, v))

map_name is the name of the map.

Parameters

The map() method requires a key-value pair of a specific map to transform to a new map.

Return type

Map.map() returns a new key-value pair.

Code

The following code shows how to use the Map.map() method in Dart:

void main() {
// Initialize map
Map map1 = {'one': 2, 'two': 6,'three': 9};
//Use .map() method
var transformedMap = map1.map((k, v) {
return MapEntry(k.toUpperCase(), v*v);
});
print(map1);
print('The transformed map: ${transformedMap}');
}

The code above changes keys and values of all entries of map1 based on the condition to create the transformedMap. This changes the keys to uppercase and multiplies the values by themselves.