我想创建一个水平滚动的卡片列表,从左或右滑动时具有捕捉到的效果。
每张卡片之间都有一定的间距,适合屏幕,如下图所示
除此之外,这些水平可滚动列表元素应包含在垂直可滚动列表内。
我所能实现的只是在遵循 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,
),
],
),
),
),
);
}
}