我有一个相对复杂的 Listview 设置,其中一个 Listview 充当水平 Listview 的滚动父级,后者充当第三个垂直 Listview 的父级。
这是布局总体思路的图片:https ://cdn.discordapp.com/attachments/752981111738466467/895739370227773480/IMG_20211007_142732.jpg 。
我无法滚动中间的 Listview,即水平 Listview(在图像中标记为 2)。
ConstrainedBox(
constraints: BoxConstraints(...),
child: ListView.builder( // This is Listview 1
controller: ScrollController(),
itemCount: itemCount,
itemBuilder: (context, worldIndex) {
return ConstrainedBox(
constraints: BoxConstraints(...),
child: ListView.builder( // This is Listview 2
controller: ScrollController(),
itemCount: ...,
scrollDirection: Axis
.horizontal, // grows horizontally to show the hierarchy of one card (the card selected in the hierarchy above it, or for the first level, the world) to its children
itemBuilder: (context, index) {
...
return ConstrainedBox(
constraints: BoxConstraints(...),
child: Padding(
padding: const EdgeInsets.all(4.0),
child: Container(
decoration: ...,
),
child: ListView.builder( // This is Listview 3
controller: ScrollController(),
itemCount: getNumChildren(index),
itemBuilder: (context, index2) {
return ...;
}),
)));
}));
}));
为简洁起见,我删除了我的代码的几个部分并用省略号替换它们。我认为这些区域中的任何一个都不太可能导致 Listview 出现任何问题,但如果可以,请告诉我。
编辑:除了水平列表视图不滚动之外,我已经正常工作的代码。我的解决方案需要在树的每个级别(例如,图像中的 1、2 和 3)都有一个可动态扩展的 Listview。主要目标平台是 Windows。
我假设这个问题涉及 Listview 赢得 GestureArena 的问题,但我目前不知道如何解决这个问题,提供一种滚动所有可用 Listview 的方法。
提前谢谢你,我希望你有一个美好的一天!