添加项目依赖

flutter_swiper : any

1

使用

dart

Container(
    width: MediaQuery.of(context).size.width,
    height: 200.0,
    child: Swiper(
        itemBuilder: (context, index) =>
            CachedNetworkImage(imageUrl: banners[index].content),
        itemCount: banners.length,
        autoplay: true,
        loop: true,
    ),
)

1234567891011

注意

必须放到 一个父元素了,不能直接放到 <Widget>[] 中作为一个子元素,原因是必须指定尺寸,即宽和高

转载请保留原文链接: https://zodream.cn/blog/id/168.html