我正在尝试在 gridview 中使用 for 循环添加数据,但它显示了一些错误。这是我的组件代码
return new GridView.count(
crossAxisCount: 2,
padding: const EdgeInsets.all(10.0),
crossAxisSpacing: 10.0,
mainAxisSpacing: 10.0,
children: <Widget>[getList()],
);
getList() 代码
List<Widget> getList() {
List<Widget> childs = [];
for (var i = 0; i < 10; i++) {
childs.add(new ListItem('abcd ' + $i));
}
return childs;
}
但它显示编译时错误。
The element type 'List<widget>' can't be assigned to the list type 'Widget'
原文由 Ravi 发布,翻译遵循 CC BY-SA 4.0 许可协议
在这里,您将列表包装为列表
这应该是