我想创建一个卡片列表,当从左边或右边刷卡时,水平滚动的卡片会以适合的效果对齐(Snap To Fit Effect).
每张卡片之间都有一定的间距,适合屏幕,如下图所示
除此之外,这些水平滚动列表元素应该包含在垂直滚动列表中.
我所能做的就是在Flutter 文档中按照下面的示例显示水平滚动卡片的列表.
class SnapCarousel extends StatelessWidget {
@override
Widget build(BuildContext context) {
final title = 'Horizontal List';
return MaterialApp(
title: title,
home: Scaffold(
appBar: AppBar(
title: Text(title),
),
body: Container(
margin: EdgeInsets.symmetric(vertical: 20.0),
height: 200.0,
child: ListView(
scrollDirection: Axis.horizontal,
children: <Widget>[
Container(
width: 160.0,
color: Colors.red,
),
Container(
width: 160.0,
color: Colors.blue,
),
Container(
width: 160.0,
color: Colors.green,
),
Container(
width: 160.0,
color: Colors.yellow,
),
Container(
width: 160.0,
color: Colors.orange,
),
],
),
),
),
);
}
}