一、竖直方向列表
class ContentView extends StatelessWidget{
@override
Widget build(BuildContext context) {
return Center(
child: ListView( // ListView必须得放到一个容器中,否则会报错
children: <Widget>[ // 里面可以放任何组件
ListTile(
leading: (
Image.asset("images/1.png")
),
trailing: Icon(
Icons.accessibility
),
title: Text("你好你好你好"),
subtitle: Text("你好,我是二级标题"),
),
ListTile(
leading: Icon(
Icons.home
),
title: Text("你好你好你好"),
subtitle: Text("你好,我是二级标题"),
),
ListTile(
leading: Icon(
Icons.web
),
title: Text("你好你好你好"),
subtitle: Text("你好,我是二级标题"),
),
ListTile(
leading: Icon(
Icons.access_alarm
),
title: Text("你好你好你好"),
subtitle: Text("你好,我是二级标题"),
),
],
),
);
}
}
二、水平方向列表
class ContentView extends StatelessWidget{
@override
Widget build(BuildContext context) {
return SizedBox(
height: 100,
child: ListView(
scrollDirection: Axis.horizontal, // 调整列表方向为水平
// reverse: true,
children: <Widget>[ // 里面可以放任何组件
Container(
width: 100,
color: Colors.red,
),
Container(
width: 100,
color: Colors.yellow
),
Container(
width: 100,
color: Colors.green
),
Container(
width: 100,
color: Colors.black
)
],
),
);
}
}