Please I'm need clarification on what the Map funtion and spread function does in flutter.
...(questions[questionIndex]['answers'] as List<String>).map((answer) {
return Answer(selectHandler: answerQuestion, answerText: answer);}).toList()
In the code above, I have Question map with keys and values, but the transformation process of the list to widget using map function with spread indicated by three dots, is what I need clarification on. Please someone help me explain to me. Thanks.
Also is there any other recommendation on transforming list to wiidget without using map function?
the spread operation let you combine a
Listelement inside anotherList, it's like you say: "merge the elements of that spread list into the main list".example :
in the other hand, the
mapmethod is not related directly to theMapobject in dart. it gives you the ability to get a copy of the original list with executing a kind of function on all elements, taking the previous list :so in your case, it's like you're saying, for all elements, create a widget that takes the answer as property and makes from it an
Answerwidget, then merge the elements of that list inside of the mainList, which can be the childrenListof aRoworColumn