Explanation
In the dart programming language, forEach is a syntax that is used to retrieve a list, or map. The data is looped according to the length of the data, which describes its contents using callback.
For more details, see the image below.
Explanation
1. data to be translated, is data in the form of a List, this data does not have to be a List, data in the form of map works too.
2. statement is written forEach, foreach must be preceded by data and followed by a dot (.)
3. callback is a statement to describe the contents/element in list.
Example of Writing
forEach on the List
Please copy and try, bro:
void main(){
List data = [3,2,1,4];
data. forEach((e){
print(e);
});
}
the output is
3
2
1
4
forEach on Map
Please copy and try, bro:
void main(){
Map<String, dynamic> data = {
"name": "gepcode",
"age": 2,
"unit of age": "month",
"number of visitors": 3000000
};
data.forEach((k, v){
print(k+": "+ v. toString());
});
}
the result is like below
name: gepcode
age: 2
unit of age: month
number of visitors: 3000000