该应用程序的目的是显示用户必须选择的许多按钮。不幸的是,无限滚动在这里不是用户友好的工具,并且优选的是不让用户做出超出必要的动作。
因此,我需要水平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
),
)
);
项目数量可能会有所不同,我不能在所有屏幕上一致地将列表划分为子列表。
看来你需要Wrap小部件。当然,widget在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()
),
),
)
);