Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从listTile导航到不同屏幕(颤振、飞镖)_List_Flutter_Dart_Routes_Navigation - Fatal编程技术网

从listTile导航到不同屏幕(颤振、飞镖)

从listTile导航到不同屏幕(颤振、飞镖),list,flutter,dart,routes,navigation,List,Flutter,Dart,Routes,Navigation,我是新来的,非常感谢你的帮助!为混乱的代码提前道歉-我正在尽我最大的努力去理解Flatter 我正在创建一个简单的测验应用程序 第一个页面以一个listTile开始,其中包含每个后续页面的标题 通过单击每个listTile,我希望导航到不同的屏幕。屏幕都在单独的dart文件中 理想情况下,我希望在以下代码中包含ontap函数,以便每个单独命名的listTile都可以显示不同的屏幕: Lesson(title: "Hosea", scoreString: "1 / 10", score: 0.1)

我是新来的,非常感谢你的帮助!为混乱的代码提前道歉-我正在尽我最大的努力去理解Flatter

我正在创建一个简单的测验应用程序

第一个页面以一个listTile开始,其中包含每个后续页面的标题

通过单击每个listTile,我希望导航到不同的屏幕。屏幕都在单独的dart文件中

理想情况下,我希望在以下代码中包含ontap函数,以便每个单独命名的listTile都可以显示不同的屏幕:

Lesson(title: "Hosea", scoreString: "1 / 10", score: 0.1),
然而,我的ontap函数只能在listTile中构建,因此我不能为每张卡单独设置它

请帮忙

**

class WelcomeScreen扩展了无状态小部件{
静态常量字符串id='welcome_screen';
@凌驾
小部件构建(构建上下文){
返回新材料PP(
标题:"小先知",,
主题:新主题数据(
primaryColor:Color.来自RGBO(58,66,86,1.0),fontFamily:“Ralway”),
主页:新列表页(标题:“课程”),
//主页:DetailPage(),
);
}
}
类ListPage扩展了StatefulWidget{
ListPage({Key-Key,this.title}):super(Key:Key);
最后的字符串标题;
@凌驾
_ListPageState createState()=>\u ListPageState();
}
类_ListPageState扩展状态{
列出经验教训;
@凌驾
void initState(){
lessons=getLessons();
super.initState();
}
@凌驾
小部件构建(构建上下文){
ListTile makeListTile(课程)=>ListTile(
内容填充:边集。对称(水平:20.0,垂直:1.0),
领先:集装箱(
填充:仅限边缘设置(右侧:12.0),
装饰:新盒子装饰(
边界:新边界(
右:新边框(宽度:1.0,颜色:Colors.white24)),
子:图标(Icons.face,color:Colors.white),
),
标题:正文(
课程名称,
样式:TextStyle(颜色:Colors.white,fontwweight:fontwweight.bold),
),
//
字幕:世界其他地区(
儿童:[
扩大(
弹性:1,
子:容器(
//标签:“英雄”,
子对象:线性表达式指示器(
背景颜色:颜色。来自RGBO(2092242240.2),
值:lesson.indicator值,
valueColor:AlwaysStoppedAnimation(Colors.green)),
)),
扩大(
弹性:4,
孩子:填充(
填充:仅限边缘设置(左:10.0),
子项:文本(lesson.level,
样式:TextStyle(颜色:Colors.white)),
)
],
),
尾随:
图标(Icons.keyboard\u arrow\u right,颜色:Colors.white,大小:30.0),
onTap:(){
},
);
卡片制作卡片(课程)=>卡片(
标高:8.0,
边距:新边集。对称(水平:10.0,垂直:6.0),
子:容器(
装饰:盒子装饰(颜色:color.fromRGBO(64,75,96,9)),
孩子:makeListTile(课程),
),
);
最终生成体=容器(
//装饰:盒子装饰(颜色:color.fromRGBO(58,66,86,1.0)),
子项:ListView.builder(
滚动方向:轴垂直,
收缩膜:对,
itemCount:lessons.length,
itemBuilder:(构建上下文,int索引){
返回制作卡(课程[索引]);
},
),
);
**
`在此处输入代码`列出getLessons(){
返回[
课程(标题:“何西阿”,分数串:“1/10”,分数:0.1),
课程(标题:“Joel”,分数串:“1/10”,分数:0.1),
课程(标题:“Amos”,分数串:“1/10”,分数:0.1),
课程(标题:“Obadiah”,分数串:“1/10”),
课程(标题:“约拿”,分数串:“1/10”),
课程(标题:“迈卡”,分数串:“1/10”),
课程(标题:“Nahum”,分数串:“1/10”),
课程(标题:“哈巴谷”,分数串:“1/10”),
课程(标题:“Zephaniah”,分数串:“1/10”),
课程(标题:“Haggai”,分数串:“1/10”),
课程(标题:“撒迦利亚”,分数串:“1/10”),
课程(标题:“Malachi”,分数串:“1/10”),
];
}
**
课堂{
字符串标题;
字符串记分字符串;
双倍得分;
课程({this.title,this.scoreString,this.score});
}

尝试传入
makeListTile(课程,索引)
并根据此索引导航到不同的屏幕

onTap(){
if(index==0)
// do something
else if(index==1)
// do something different
}
onTap(){
if(index==0)
// do something
else if(index==1)
// do something different
}