我想创建一个水平滚动列表,当从左侧或右侧滑动时,使用捕捉以适应效果.
每张卡片之间有一些间距,适合屏幕,类似于下图
除此之外,这些可水平滚动的列表元素应包含在垂直可滚动列表中.
我所能实现的只是在flutter docs中跟随示例之后才显示水平滚动卡列表.
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,
),
],
),
),
),
);
} …
Run Code Online (Sandbox Code Playgroud) dart flutter flutter-sliver flutter-layout flutter-animation