这是常用的一些,如果需要深入研究,请移步github
// 可以在此代码上封装成函数,功能部分自行删减
Container(
height: 200, // 设置图片显示的高度
child: Swiper(
itemBuilder: (BuildContext context, int index) {
return new Image.network(
"${imageList[index]}", // 外部定一个imageList,可以是网上获取的
fit: BoxFit.fill, // 常用BoxFit.cover
);
},
onTap: () {},
duration: 300, // 单位毫秒
control: SwiperControl(), // 显示上一张下一张按钮
pagination: SwiperPagination(), // 底部显示小点点
itemCount: imageList.length, // 轮播图的数量
autoplay: true, // 自动播放
// layout: SwiperLayout.STACK, // 轮播图的样式,可能需要设置itemWidth和itemHeight等
),
);