该应用程序的目的是显示用户必须选择的许多按钮。不幸的是,无限滚动在这里并不是用户友好的工具,因此最好不要让用户进行超出必要的操作。
这样,我需要将水平ListView放在一个屏幕内并在其下方展开,以添加新行。我尝试添加一个SizedBox,但是ListView行仍然是无限的,并且不在屏幕上。
return new Scaffold(
appBar: AppBar(
title: Text("Test"),
),
body: SizedBox(
width: 300.0,
child: ListView(
scrollDirection: Axis.horizontal,
children: _rowWidgets.toList() // these are just IconButtons
),
)
);
项目的数量可能会有所不同,因此我无法在所有屏幕上始终将列表划分为子列表。
答案 0 :(得分:1)
似乎您需要Wrap小部件。当然,小部件没有像ListView那样的水平滚动。因此,您必须提供垂直滚动才能显示很多按钮。
return Scaffold(
appBar: AppBar(
title: Text("Test"),
),
body: Center(
child: Container(
padding: EdgeInsets.all(16.0),
color: Colors.green,
width: 300.0,
child: Wrap(
spacing: 8.0, // gap between adjacent chips
runSpacing: 4.0, // gap between lines
children: List.generate(9, (i) => item(i.toString())).toList()
),
),
)
);