直播软件开发,自动滚动banner

直播软件开发,自动滚动banner实现的相关代码

@override
  Widget build(BuildContext _buildContext) {
    int banLen = _banner.length;
    double width = ViewUtils.getScreenWidth(_buildContext);
    double curWidth = width * 0.92;
    double curHeight = curWidth * 187 / 670;
    return (banLen > 0)
        ? Container(
            margin: EdgeInsets.only(top: ViewUtils.currentHeight(38.0)),
            width: width,
            height: curHeight,
            child: Column(
              children: <Widget>[
                Expanded(
                  flex: 1,
                  child: Swiper(
                    containerHeight: ViewUtils.currentHeight(100.0),
                    controller: SwiperController(),
                    itemBuilder: (BuildContext context, int index) {
                      return _itemBuilder(index,curWidth,curHeight);
                    },
                    loop: true,
                    duration: 300,
                    autoplay: true,
                    scrollDirection: Axis.horizontal,
                    itemCount: banLen,
                    viewportFraction: 0.92,
                    // 当前视窗展示比例 小于1可见上一个和下一个视窗
                    scale: 0.96, // 两张图片之间的间隔
                  ),
                ),
              ],
            ),
          )
        : Container();
  }

​    最后设置圆角

_itemBuilder(_index,_curWidth,_curHeight ){
    String imgUrl = _banner[_index].imgUrl;
    return GestureDetector(
      onTap: () {
        
      },
      child: Container(
        width: _curWidth,
        height: _curHeight,
        decoration: BoxDecoration(
            gradient: const LinearGradient(
                colors: [Color(0xFF819FF5), Color(0xFF4A66E7)]),
            borderRadius: BorderRadius.all(
              Radius.circular(10),
            ),
            image: DecorationImage(
              image: NetworkImage(imgUrl),
              fit: BoxFit.fitWidth,
            )),
      ),
    );
  }

以上就是直播软件开发,自动滚动banner实现的相关代码, 更多内容欢迎关注之后的文章

 

posted @ 2022-03-04 14:06  云豹科技-苏凌霄  阅读(50)  评论(0)    收藏  举报