将小部件添加到列表中

问题描述 投票:1回答:1

我有这样的课

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

如何将它们添加到列表中并分配给children: <Widget>[]。例如,而不是

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

我想要

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

更新:

列表像这个List list=['view1()','view(2)']的创建

当我尝试时,我得到了The argument type 'String' can't be assigned to the parameter type 'Widget'.

children: <Widget>[
        Container(
         child: list,
          )]
flutter
1个回答
1
投票

您可以使用

    children:list // list is widget list in your case
© www.soinside.com 2019 - 2024. All rights reserved.