16. Flutter - Dynamic Return Widgets from a List
1. Create a List variable.
2. Let flutter automatically create a bunch of Text() widgets using the texts from the List.
3. Column() widget's children's property requires a LIST of widgets.
4. Use a map method on the created List.
List<Strings> alist = [
"APPLE",
"BANANA",
"SPOON",
];
children property will use:
children: alist.map((listvalue){
return Text(listvalue);
}).toList(),
Explaination:
(dot)map((){}) // when added to a list, it will go through the list and for every item in the list, it will perform a function using that value, Define the parameter for the value in parenthesis. Define a function in the brackets.
(dot).toList() // when added after, it will turn the list of functions into a List that the children property can use.
Comments
Post a Comment