android – 元素类型’List’不能分配给列表类型’Widget’

android – 元素类型’List’不能分配给列表类型’Widget’,第1张

概述我试图在gridview中使用for循环添加数据,但它显示出一些错误.这是我的组件代码 return new GridView.count( crossAxisCount: 2, padding: const EdgeInsets.all(10.0), crossAxisSpacing: 10.0, mainAxisSpacing: 10.0, childr 我试图在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(),
总结

以上是内存溢出为你收集整理的android – 元素类型’List’不能分配给列表类型’Widget’全部内容,希望文章能够帮你解决android – 元素类型’List’不能分配给列表类型’Widget’所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1000491.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存