可以透過scrollDirection來設定垂直或水平滾動列表資料。
class HomePage extends StatelessWidget {
//列表集合資料
List<Widget> list = <Widget>[
ListTile(
title: Text(
'title1',
style: TextStyle(fontWeight: FontWeight.w600, fontSize: 20.0),
),
subtitle: Text('subtitle1'),
),
ListTile(
title: Text(
'title2',
style: TextStyle(fontWeight: FontWeight.w600, fontSize: 20.0),
),
subtitle: Text('subtitle12'),
),
];
@override
Widget build(BuildContext context) {
return Center(
//列表元件
child: ListView(
children: list,
),
);
}
}
class HomePage extends StatelessWidget {
//列表集合資料
List<Widget> list = <Widget>[
ListTile(
title: Text(
'title1',
style: TextStyle(fontWeight: FontWeight.w600, fontSize: 20.0),
),
subtitle: Text('subtitle1'),
),
ListTile(
title: Text(
'title2',
style: TextStyle(fontWeight: FontWeight.w600, fontSize: 20.0),
),
subtitle: Text('subtitle12'),
),
];
@override
Widget build(BuildContext context) {
return Center(
//列表元件
child: ListView(
scrollDirection: Axis.horizontal,
children: list,
),
);
}
}