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)
mapis the name of the map.
Parameters
The map.fromIterables() method requires the key and value to create a map.
You must pass
keyandvalueparameters to determine what should be thekeyandvalue.
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 akeywill be utilized.
Code
The following code illustrates the fromIterable() method’s use in Dart:
void main() {// Creating iterablesList<String> numbers = ['five', 'three', 'seven', 'one'];List<String> fruits = ['Apple', 'Orange', 'Lemon', 'Pawpaw'];// Creating a map from the iterables// using fromIterables() methodMap<String, String> map = new Map.fromIterables(numbers, fruits);print(map);}
Note: Both Iterables must have the same length.