'convert list of strings to list of widgets in flutter dart [duplicate]
I have simple method like this:
List<Widget> stringsToWidgets( List<String>? a) {
List<Text> b = [];
for (var item in a) {
b.add(Text(item));
}
return b;
}
Column(children: stringsToWidgets(["1", "2", "3"]));
I have column, and children of it come from this method.
How to do it faster in place, without this stringsToWidgets method?
Solution 1:[1]
Ok, finally I found solution:
Column(
children:
for ( var i in ["1", "2", "3"] )
Text(i)
);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Miroslav Blagoev |
