返回类型'对象' Isn; ta; ta; ta; widget; widget;
我尝试使用list.generate构建,但它们有错误的返回类型“对象”不是“窗口小部件”,这是封闭情况下的要求。但是,当我使用listView.builder时,我的应用程序正常工作。
Here my code
List.generate(
data.length,
(index) {
return GestureDetector(
child: Padding(
padding: const EdgeInsets.only(
bottom: 20, left: 20, right: 20),
child: CustomPromotionNew(
thumbNail: (snapshot.data as List)[index].imgUrl,
title:
(snapshot.data as List)[index].promotionName,
),
),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
PromotionNewsDetailScreen(
items:
(snapshot.data as List)[index]),
));
},
);
},)
: const Center(
child: CircularProgressIndicator(),
);
I try to build with List.generate but they has error The return type 'Object' isn't a 'Widget', as required by the closure's context. But when i use ListView.builder, my application work fine.
Here my code
List.generate(
data.length,
(index) {
return GestureDetector(
child: Padding(
padding: const EdgeInsets.only(
bottom: 20, left: 20, right: 20),
child: CustomPromotionNew(
thumbNail: (snapshot.data as List)[index].imgUrl,
title:
(snapshot.data as List)[index].promotionName,
),
),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
PromotionNewsDetailScreen(
items:
(snapshot.data as List)[index]),
));
},
);
},)
: const Center(
child: CircularProgressIndicator(),
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您会遇到此错误,因为您已定义了列表中的widget树类型。而不是您需要定义ListView。为了解决此错误,您需要在代码下方放置
You getting this error because you have defined list type in widget tree. instead of that you need to define listview. For solve this error you need to put below code