Explanation
In darts, looping uses a map, functionally the same as forEach. However, maps can refactor data.
So to refactor a data, in every callback, there must be a return of the value of that data, because every callback in the map has a data type dynamic.
Image Explanation
1. Refactor data after refactoring
2. data to be refactored
3. map statement
4. the logic in the map loop that returns data is julio if the element (e) name is arthur.
5. returns data, if condition if is not executed
6. change the resulting map into a list.
Could you copy the code below?
void main(){
List data = ['alex', 'ferguso', 'arthur'];
var replaced = data. map((e){
if(e == 'arthur') return 'julio';
return e;
}).toList();
print(replaced);
}
the result is
[alex, ferguso, julio]