Flutter 组件之Swiper轮播图

朱雀 2023-07-18 11:15 217阅读 0赞

flutter_swiper: ^1.1.6

  1. //引入第三方包
  2. import 'package:flutter_swiper/flutter_swiper.dart';
  3. //图片列表
  4. List<Map> imgList = [
  5. {
  6. "url":"https://timgsa.baidu.com/4.jpg",
  7. },
  8. {
  9. "url":"https://timgsa.baidu.com/519.jpg",
  10. },
  11. {
  12. "url":"https://timgsa.baidu.com/timg003683.jpg",
  13. },
  14. {
  15. "url":"https://timgsa.baidu.com/timg04d.jpg",
  16. },
  17. ];
  18. new Column(
  19. children: <Widget>[
  20. Expanded(
  21. child: new Swiper(
  22. itemBuilder: (BuildContext context, int index) {
  23. return new Image.network(
  24. imgList[index]["url"],
  25. fit: BoxFit.fill,//图片填充
  26. );
  27. },
  28. autoplay: true,//自动播放
  29. itemCount: imgList.length,
  30. pagination:
  31. new SwiperPagination(builder: SwiperPagination.fraction),//分页器样式
  32. control: new SwiperControl(),//左右箭头
  33. )),
  34. Expanded(
  35. child: new Swiper(
  36. itemBuilder: (BuildContext context, int index) {
  37. return new Image.network(
  38. imgList[index]["url"],
  39. fit: BoxFit.fill,
  40. );
  41. },
  42. autoplay: true,//自动能播放
  43. loop: true,//循环播放
  44. itemCount: imgList.length,
  45. scrollDirection: Axis.vertical,//竖向轮播
  46. pagination: new SwiperPagination(//分液器
  47. alignment: Alignment.centerRight,
  48. builder: SwiperPagination.fraction),
  49. ))
  50. ],
  51. ));

发表评论

表情:
评论列表 (有 0 条评论,217人围观)

还没有评论,来说两句吧...

相关阅读