【发布时间】:2022-11-15 04:00:39
【问题描述】:
在我的应用程序中,我在 appBar 中列出了几个具有产品类别名称的容器,这些类别与它们各自的产品一起列在正文中。
appBar 中的 ListView 与主体的 ListView 具有相同的索引,因此我们的想法是按下 appBar 中的索引“x”,用户将被重定向到主体中的索引“x”。
我尝试了很多解决方案,其中一个是包https://pub.dev/packages/scrollable_positioned_list,但它没有用,因为当调用函数滚动时,我的列表就消失了。
这是代码:
return Scaffold(
backgroundColor: Colors.white,
appBar: PreferredSize(
preferredSize: Size.fromHeight(120),
child: Column(
children: [
AppBar(...),
Expanded(
child: Container(
color: AppColors.primary,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: widget.listaProdutos.length,
itemBuilder: (context, index) {
return Padding(
padding: EdgeInsets.symmetric(...),
child: GestureDetector(
child: Container(
decoration: BoxDecoration(...),
child: Padding(...),
child: Center(
child: Text(
widget.listaProdutos[index].dsGrupo,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
),
),
),
onTap: () {
SHOULD SCROLL TO INDEX
},
),
);
},
)
),
),
],
),
),
body: SingleChildScrollView(
child: Column(
children: [
Container(
child: ListView.builder(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: widget.listaProdutos.length,
itemBuilder: (context, indexGrupo) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Card(...),
ListView.builder(..),
],
);
},
),
),
],
),
),
);
【问题讨论】:
-
这回答了你的问题了吗? flutter ListView scroll to index not available