我试图在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'
解决方法
在这里,您将列表包装为列表
children: <Widget>[getList()],
这应该是
children: getList(),