The syntax of Map.Map.fromEntries constructor is:
Map.fromEntries(Iterable<MapEntry<K, V>> entries)
This Map.fromEntries constructor of Map creates a new map and adds all entries.
Parameter | Optional/Required | Description |
---|---|---|
entries | required | An iterable of MapEntry objects representing key-value pairs to be added to the new map. |
In this example,
Map.fromEntries()
with the provided entries.void main() {
var entries = [MapEntry('a', 1), MapEntry('b', 2), MapEntry('c', 3)];
var map = Map.fromEntries(entries);
print('Map from entries: $map');
}
Map from entries: {a: 1, b: 2, c: 3}
In this example,
Map.fromEntries()
with the provided entries.void main() {
var entries = [MapEntry(1, 'one'), MapEntry(2, 'two'), MapEntry(3, 'three')];
var map = Map.fromEntries(entries);
print('Map from entries: $map');
}
Map from entries: {1: one, 2: two, 3: three}
In this example,
Map.fromEntries()
with the provided entries.void main() {
var entries = [MapEntry(true, 'yes'), MapEntry(false, 'no')];
var map = Map.fromEntries(entries);
print('Map from entries: $map');
}
Map from entries: {true: yes, false: no}
In this Dart tutorial, we learned about Map.fromEntries constructor of Map: the syntax and few working examples with output and detailed explanation for each example.