你好,我想知道如何在列表视图构建器中实现导航,这是我尝试过的。
Widget build(BuildContext context) {
return Scaffold(
body:Container(
padding: EdgeInsets.all(10.0),
color: AppColors.whiteColor,
child: Column(
children: <Widget>[
Flexible(
child: AnimationLimiter(
child: ListView.builder(
shrinkWrap: false,
padding: const EdgeInsets.all(8.0),
itemCount: menuList.length,
itemBuilder: (BuildContext context, int index) {
return AnimationConfiguration.staggeredList(
position: index,
duration: const Duration(milliseconds: 375),
child: SlideAnimation(
verticalOffset: 44.0,
child: FadeInAnimation(
child: GestureDetector(
onTap: (){
Navigator.push(
context,
MaterialPageRoute(builder: (context) => menuList[index].name(menuList[index].children,widget.name,widget.code)),
);
},
child: Card(
margin: EdgeInsets.only(bottom: SizeConfig.blockSizeVertical*2),
child: ListTile(
leading: Image.network(menuList[index].icon),
title: Text(menuList[index].name),
),
),
),
),
));
},
),
),
)
],
),
),
我对你的问题的理解是,你想根据每个索引上不同的API值打开不同的活动。为什么不在你的onTap()中加入一个IF条件来检查每个元素上的某个值,以指示导航的位置。比如说,你的onTap()中的IF条件是 if (widget.studentTestInfo.content[index].canSeeResultTr == true) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ResultPageLook(
studentProfile: widget.studentProfile,
studentTestInfo: widget.studentTestInfo,
),
)
);
} else {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => TestSyllabus(
studentProfile: widget.studentProfile,
studentTestInfo: widget.studentTestInfo,
),
),
);
}