aoiTenshi
aoiTenshi

Reputation: 667

How to assign list of widgets as a child of Column?

I have a list of Widgets and I want to use it as one of the children of a Column. Like this:

List<Widget> wList = [];
Column(
    children([
        Text("hi"),
        //elements of wlist
    ])
)

I want to map it to use elements of list. What would be the syntax?

Upvotes: 1

Views: 995

Answers (3)

ghadeerMayya
ghadeerMayya

Reputation: 81

3 dots operator will solve it shortly ... Try it like this

 List<Widget> wList = []; // add your widgets here
    Column(
        children([
            Text("hi"),
            ...wList
        ])
    )

Upvotes: 4

Abdulazeez Salam
Abdulazeez Salam

Reputation: 134

You pass the list of widgets into a named argument called children. The syntax would be:

    Column(
       children: <Widget>[Text('Hello'), Text('World')]
       )

With named arguments, you write the name of the argument and then a colon (:) and then the value you want to pass.

Upvotes: 0

Piotr
Piotr

Reputation: 667

Just add it as

Column(
 children: wList,
);

If you need additional widgets in said column with widget list you can always use it like:

 Column(
     children: [add widgets here] + wList,
    );

Or the other way around to add list before widgets in the column.

Upvotes: 1

Related Questions