Reputation: 15091
The following is a pseudo code that I want to have.
void main() => runApp(
Container(
child: ListView(
children: [Text('Start'),...[1,2,3].forEach((element) {Text('$element')}), Text('Finish')],
),
),
);
Here I want to insert a list of Text
without having to write a method or a property. Is it possible in Dart?
Upvotes: 0
Views: 37
Reputation: 17123
You can use the map
method from Iterable
in conjunction with the spread operator you already have.
[Text('Start'),...[1,2,3].map((element) {return Text('$element');}), Text('Finish')]
Upvotes: 3