动态列表视图生成器导航

Dynamic Listview Builder Navigation

您好,我想知道如何在列表视图生成器中实现导航,这是我尝试过的方法。

 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 值打开不同的 activity。为什么不在您的 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, ), ), ); }