What is map.fromIterables() method in Dart?

fromIterables() is a method in Dart that creates a Map instance from an Iterable.

Syntax

map.remove(key, value)

map is the name of the map.

Parameters

The map.fromIterables() method requires the key and value to create a map.

You must pass key and value parameters to determine what should be the key and value.

Return value

The Dart method map.fromIterables() iterates over keys and values. It maps each element of the keys to the corresponding elements of the values.

If there are multiple elements with the same key, the last occurrence of a key will be utilized.

Code

The following code illustrates the fromIterable() method’s use in Dart:

void main() {
// Creating iterables
List<String> numbers = ['five', 'three', 'seven', 'one'];
List<String> fruits = ['Apple', 'Orange', 'Lemon', 'Pawpaw'];
// Creating a map from the iterables
// using fromIterables() method
Map<String, String> map = new Map.fromIterables(numbers, fruits);
print(map);
}

Note: Both Iterables must have the same length.