Alex
Alex

Reputation: 827

Add widget into list

I have some class like this

class View1 extends StatelessWidget {
  @override
  Widget build(BuildContext ctx) {
    return Center(child: Text('Something'));
  }
}
class View2 extends StatelessWidget {
....
}

How can I add them into a list and assigned to the children: <Widget>[]. For example, instead of

children: <Widget>[
                   view1() 
                   //or view2 
             ]

I want

children: <Widget>[
                   //for loop or something
                   list[i] 
                 ]

UPDATE:

The List a creat like this List list=['view1()','view(2)']

and I got The argument type 'String' can't be assigned to the parameter type 'Widget'. when I try

children: <Widget>[
        Container(
         child: list,
          )]

Upvotes: 1

Views: 48

Answers (1)

Xuzan
Xuzan

Reputation: 335

You can use

    children:list // list is widget list in your case

Upvotes: 1

Related Questions