Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swiper 组件 #49

Open
gaowei1012 opened this issue Oct 14, 2020 · 2 comments
Open

Swiper 组件 #49

gaowei1012 opened this issue Oct 14, 2020 · 2 comments

Comments

@gaowei1012
Copy link
Owner

gaowei1012 commented Oct 14, 2020

基本使用

Container(

                /// 宽度
                width: MediaQuery.of(context).size.width,
                height: 120,
                margin: EdgeInsets.only(bottom: 20),
                child: Swiper(
                  itemCount: 3, // 轮播个数
                  loop: true, // 循环播放
                  autoplay: true, // 自动轮播
                  scrollDirection: Axis.horizontal, // 轮播方向 ho
                  itemBuilder: _swiperBuilder,
                  /// 指示器
                  pagination: SwiperPagination(
                      builder: DotSwiperPaginationBuilder(
                          color: Colors.black12, activeColor: Colors.white)),
                  // control: SwiperControl(),
                )),


/// 循环内容
  Widget _swiperBuilder(BuildContext context, int index) {
    return (Image.network(
      'http://via.placeholder.com/350x150',
      fit: BoxFit.fill,
    ));
  }
@gaowei1012
Copy link
Owner Author

gaowei1012 commented Oct 14, 2020

进阶用法

Container(
              width: MediaQuery.of(context).size.width,
              height: 200,
              margin: EdgeInsets.only(bottom: 20),
              child: Swiper(
                itemCount: 6,
                autoplay: true,
                loop: true,

                /// 内建样式
                layout: SwiperLayout.STACK,
                itemWidth: 300,
                itemHeight: 400,
                scrollDirection: Axis.horizontal,
                itemBuilder: _swiperBuilderB,
                pagination: SwiperPagination(
                    builder: DotSwiperPaginationBuilder(
                        color: Colors.black12, activeColor: Colors.white)),
              ),
            )


  Widget _swiperBuilderB(BuildContext context, int index) {
    return (Image.network(
      'http://via.placeholder.com/350x150',
      fit: BoxFit.fill,
    ));
  }

@gaowei1012
Copy link
Owner Author

gaowei1012 commented Oct 14, 2020

自定义用法

Container(
              width: MediaQuery.of(context).size.width,
              height: 160,
              child: Swiper(
                itemCount: 6,
                loop: true,
                autoplay: true,
                layout: SwiperLayout.CUSTOM,
                itemWidth: 300,
                itemHeight: 160,
                itemBuilder: _swiperBuilderC,
                scrollDirection: Axis.horizontal,
                pagination: SwiperPagination(
                    builder: DotSwiperPaginationBuilder(
                        color: Colors.black12, activeColor: Colors.white)),

                /// 自定义轮播效果
                /// 描述布局和动画
                customLayoutOption: CustomLayoutOption(
                        startIndex: -1, stateCount: 3)
                    .addRotate([-45.0 / 100, 0.0, 45.0 / 100]).addTranslate([
                  Offset(-370.0, -40.0),
                  Offset(0.0, 0.0),
                  Offset(370.0, -40.0)
                ]),
              ),
            )


Widget _swiperBuilderC(BuildContext context, int index) {
    return (Image.network(
      'http://via.placeholder.com/350x150',
      fit: BoxFit.fill,
    ));
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant