
一、首先在yaml中导入 flutter_swiper: ^1.1.6组件
二、在body中使用Swiper
class HomePage extends StatefulWidget {
HomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
List _images = [
"*/id_1986_202108131552359122.jpg",
"*/202108121501016824.jpeg",
"*/202108121501016824.jpeg",
"*/202108121501011517.jpeg",
];
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
children: [
Container(
height: 169,
child: Swiper(
itemCount: _images.length,
autoplay: true,
onTap: (index){
//图片点击事件
print("object$index");
},
itemBuilder: (BuildContext context, int index) {
return Image.network(
_images[index],
fit: BoxFit.cover,
);
},
//指示器
pagination: SwiperPagination(),
),
)
],
),
),
);
}
}
本文介绍了如何在Flutter应用中使用swiper组件实现图片轮播,并展示了如何设置autoplay、监听点击事件和自定义itemBuilder。通过实例代码,读者将学会如何优雅地集成和定制Swiper组件。

2975

被折叠的 条评论
为什么被折叠?



