路由错误显示缺少一个参数? [英] Routing error shows missing one argument?
问题描述
这是我转到下一页的方式,
This is how i am routing to next page ,
'/ot1': (context) => CustomListView(),
,并且在TAP上运行良好
and it was working fine onTAP
onTap: (){
Navigator.pushNamed(context, '/ot1');
},
但是当我在 Class CustomListView
并通过传递的字段,我收到此错误,此行中缺少一个参数'/ ot1':(context)=> CustomListView(),
but when i created constructor in class CustomListView
and passed field i got this error that one argument is missing in this line '/ot1': (context) => CustomListView(),
这是我下面的类CustomListView
共享的代码
this is the code of my class CustomListView
share below
class CustomListView extends StatelessWidget {
final List<Spacecraft> spacecrafts;
CustomListView(this.spacecrafts);
Widget build(context) {
return ListView.builder(
itemCount: spacecrafts.length,
itemBuilder: (context, int currentIndex) {
return createViewItem(spacecrafts[currentIndex], context);
},
);
}
我已经搜索了很多东西,却没有找到新的解决方案编程和FLUTTER语言,请帮助
I have searched for it for so much and didn't find a solution new to programming and FLUTTER language please HELP
推荐答案
尝试添加方括号[this.spacecrafts],以使spacecraft参数成为可选参数
Try adding square brackets [this.spacecrafts] so that the spacecraft argument becomes an optional argument.
class CustomListView extends StatelessWidget {
final List<Spacecraft> spacecrafts;
CustomListView([this.spacecrafts]); # <- this is where you use the brackets
...
这篇关于路由错误显示缺少一个参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!