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