【flutter 入门】listview

横向

// 展示ListView
class horizontalList extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ListView(
scrollDirection: Axis.horizontal, //设置为横向,默认使纵向
children: <Widget>[
new ListItem(context,
"https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=1381175915,2452671132&fm=200&gp=0.jpg"),
new ListItem(context,
"https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=1486063646,2273285260&fm=200&gp=0.jpg"),
new ListItem(context,
"https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=174198655,918435950&fm=200&gp=0.jpg"),
new ListItem(context,
"https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=2970139869,654827709&fm=200&gp=0.jpg"),
new ListItem(context,
"https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=768870055,119193172&fm=200&gp=0.jpg"),
],
);
}
}

2.嵌套 
子listview需要有确切size 

 return SizedBox(

// 不给高度的话显示不了哈, 就跟 android 里, scrollview 里嵌套 listview 一样, 要计算高度的意思, 这里我就先随便给个, 其实我觉得应该是要根据 item 的高度来算的, 但我现在不会算啊

height: 100.0,

child: ListView.builder(

scrollDirection: Axis.horizontal,

itemBuilder: (context, position) {

return _buildHorItem(position);

},

itemCount: horList.length,

),

);

没有SizedBox 报错。

原文地址:https://www.cnblogs.com/mamamia/p/14467370.html