如何迭代列表以将其合并到包装小部件中?
How to iterate over list to incorporate it in a wrap widget?
我正在尝试将 Row 中的项目(容器)限制为 8 个,如果有更多项目,则应将它们包装起来。我有一个容器列表,但我不能将 listView 用作 Wrap 的子项,因为 listView 会滚动。有什么办法可以修复此布局?
我试过使用 for 循环,但是当它第一次达到 return 时,它就跳出了循环。
我试过使用 gridView 而不是 wrap,但它没有给我结果,因为 gridView 是可滚动的。
Expanded(
flex: 4,
child: Wrap(
direction: Axis.horizontal,
spacing: 0.5,
runSpacing: 0.5,
crossAxisAlignment: WrapCrossAlignment.center,
children: <Widget>[
// I want something that works like following line
//Container(child: kids1)
//currently I can get results with following code
kids1[1],
kids1[2],
kids1[3], kids1[4], kids1[5], kids1[6],
kids1[7], kids1[8], kids1[9], kids1[10],
kids1[11]
],
),
),
kids 是容器列表
为什么不在构建函数的 return 之前创建子列表:
@override
Widget build(BuildContext context) {
List<Widget> children = List.generate(myContainerList.length, (e) => myContainerList[e]);
return Wrap(
children: children,
);
}
我正在尝试将 Row 中的项目(容器)限制为 8 个,如果有更多项目,则应将它们包装起来。我有一个容器列表,但我不能将 listView 用作 Wrap 的子项,因为 listView 会滚动。有什么办法可以修复此布局?
我试过使用 for 循环,但是当它第一次达到 return 时,它就跳出了循环。
我试过使用 gridView 而不是 wrap,但它没有给我结果,因为 gridView 是可滚动的。
Expanded(
flex: 4,
child: Wrap(
direction: Axis.horizontal,
spacing: 0.5,
runSpacing: 0.5,
crossAxisAlignment: WrapCrossAlignment.center,
children: <Widget>[
// I want something that works like following line
//Container(child: kids1)
//currently I can get results with following code
kids1[1],
kids1[2],
kids1[3], kids1[4], kids1[5], kids1[6],
kids1[7], kids1[8], kids1[9], kids1[10],
kids1[11]
],
),
),
kids 是容器列表
为什么不在构建函数的 return 之前创建子列表:
@override
Widget build(BuildContext context) {
List<Widget> children = List.generate(myContainerList.length, (e) => myContainerList[e]);
return Wrap(
children: children,
);
}