flutter - 如何在 ListView.builder 中从上一个列表停止的位置开始 itemCount?
问题描述
我有 2 行显示兴趣的 Listview 构建器(可水平滚动)。
希望第一行显示前 6 个兴趣,下一行显示列表中的其余部分。
如何将第二个中的 itemCount 设置为从 7 一直到最后的范围?
任何帮助表示赞赏。代码片段如下:
Padding(
padding: const EdgeInsets.fromLTRB(6, 6, 0, 0),
child: Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height * 0.045,
child: ListView.builder(
shrinkWrap: true,
scrollDirection: Axis.horizontal,
padding: const EdgeInsets.all(1),
itemCount: 6,
itemBuilder: (context, int index) {
return Interests2(AvailableInterestChosen(
allInterests[index],
isChosen: false,
));
}),
),
),
Padding(
padding: const EdgeInsets.fromLTRB(6, 3, 0, 0),
child: Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height * 0.045,
child: ListView.builder(
shrinkWrap: true,
scrollDirection: Axis.horizontal,
padding: const EdgeInsets.all(1),
**// itemCount: allInterests range from 6 to end of list,**
itemBuilder: (context, int index) {
return Interests2(AvailableInterestChosen(
allInterests[index],
isChosen: false,
));
}),
),
),
...
第二个填充中的粗体部分是我在构建范围时遇到问题的地方。
解决方案
作为第二个列表视图的参数,您可以使用 allInterests.size()-6 来计算项目数,使用 index + 6 来访问 allInterests 列表的索引。
推荐阅读
- visual-studio-code - VS Code:如何同时滚动拆分面板
- python - 用字符串列表标记 Matplotlib 子图 y 轴
- python-3.x - 是否可以使用 Python 中的 ObjectId 字符串更新 MongoDB 字符串字段
- blockchain - 在 Ropsten 网络上部署智能合约
- reactjs - 如何根据 React 中方法的返回值禁用/启用按钮?
- apache-kafka - 代理地址更改后,Kafka Producer 无法重新连接和刷新元数据
- python - 有没有办法使用 python 读取受密码保护的 excel 文件?
- c# - 如何在 C# 中获取 File.Create("Score.txt") 的路径
- rust - 我可以在同一个 fn 中使用 `write!` 和 `file.write_all` 吗?
- angularjs - 为什么javascript中的打印功能在edge中不起作用,但在chrome中起作用