一、首先在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(),
),
)
],
),
),
);
}
}