flutter - 将小部件添加到列表中
问题描述
我有这样的课
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,
)]
解决方案
您可以使用
children:list // list is widget list in your case
推荐阅读
- spring-boot - Spring引导休息调用中的无效mimetype异常
- postgresql - 表的浮动模式定义 - 如何在 pl/sql 中
- javascript - 为什么 Diff-match-patch 破坏 linediff 超过 65K 行
- java - 更改 java List 的输出顺序
- python - 装饰者:为什么我得到不同的结果?如果我传递一个带参数的函数,@ 符号是强制性的吗?
- python - 从另一个函数引用 ttk.Treeview 列
- python - Django Admin 多模板继承
- javascript - 如何在错误的表格中设置单元格的颜色
- r - ggplot 使用 facet_wrap 的非字母顺序
- unix - 编写 awk 命令找到编号。文件中的分隔符