Display Name
Display Name

Reputation: 15091

Is it possible to insert a list of widgets without having to define a method or property?

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

Answers (1)

Christopher Moore
Christopher Moore

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

Related Questions