我需要创建一个页面,其中包含按单行分组的对象列表。需要垂直和水平滚动以显示更多的分组和分组子项。垂直和水平滚动需要同时移动所有项目。类似于这样:https://gph.is/g/46gjW0q
我使用以下代码来实现这一点:
那么如何使用动态的ListView宽度来实现这个呢?
Widget _buildGroups() {
return SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Container(
width: 2000,
child: ListView.builder(
scrollDirection: Axis.vertical,
itemCount: boardData.length,
itemBuilder: (context, index) {
return Row(children: _buildSingleGroup(index));
},
),
),
);
}
List<Widget> _buildSingleGroup(int groupIndex) {
return List.generate(...);
}
我需要这个元素在水平方向上具有动态性,但是如您所见,如果不设置宽度,会导致错误:
══════════════════ Exception caught by rendering library ═════════════════════
The following assertion was thrown during performResize()
Vertical viewport was given unbounded width.
Viewports expand in the cross axis to fill their container and constrain their
children to match their extent in the cross axis. In this case, a vertical
viewport was given an unlimited amount of horizontal space in which to expand.
我尝试在ListView中设置"shrinkWrap: true",但结果出现了另一个错误:
Failed assertion: line 1629 pos 16: 'constraints.hasBoundedWidth': is not true.
那么如何使用动态的ListView宽度来实现这个呢?