【Flutter】三十九、Flutter常用组件——轮播组件flutter_swiper

一、安装flutter_swiper

flutter_swiper: ^1.1.6
flutter pub get

二、使用

import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';

class SwiperRoute extends StatefulWidget{
  @override
  _SwiperRouteState createState() {
    // TODO: implement createState
    return _SwiperRouteState();
  }
}

class _SwiperRouteState extends State<SwiperRoute>{
  List<ImageProvider> list = [
    AssetImage('assets/images/lake.jpg'),
    AssetImage('assets/images/img1.jpg'),
    AssetImage('assets/images/img2.jpg')
  ];
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text('SwiperDemo'),
      ),
      body: Container(
        width: double.infinity,
        height: 250,
        child: Swiper(
          autoplay: true,
          itemBuilder: (BuildContext context,int index){
            return Stack(
              children: <Widget>[
                Container(
                  margin: EdgeInsets.all(10),
                  decoration: BoxDecoration(
                      boxShadow: [
                        BoxShadow(offset: Offset(1, 1), color: Colors.black12, spreadRadius: 3.0, blurRadius: 7.0),
                        BoxShadow(offset: Offset(-1, -1), color: Colors.black12, spreadRadius: 3.0, blurRadius: 7.0),
                        BoxShadow(offset: Offset(-1, 1), color: Colors.black12, spreadRadius: 3.0, blurRadius: 7.0),
                        BoxShadow(offset: Offset(1, -1), color: Colors.black12, spreadRadius: 3.0, blurRadius: 7.0),
                      ],
                      borderRadius: BorderRadius.circular(15.0),
                      image: DecorationImage(image: list[index],fit: BoxFit.cover)
                  ),
                ),
                Align(
                  alignment: Alignment.center,
                  child: Text('$index', style: TextStyle(color: Colors.white, fontSize: 95.0)),
                )
              ],
            );
          },
          itemCount: 3,
          fade: 0.0,
          scale: 0.0,
          curve: Curves.easeInOut,
          duration: 600,
          autoplayDelay: 5000,
          pagination: SwiperPagination(
            margin: EdgeInsets.symmetric(horizontal: 20, vertical: 30)
          ),
        ),
      )
    );
  }
}

效果:
在这里插入图片描述

三、Swiper属性说明

Swiper({
    this.itemBuilder,
    this.indicatorLayout: PageIndicatorLayout.NONE,

    this.transformer,
    @required this.itemCount, // 轮播数量
    this.autoplay: false, // 自动播放
    this.layout: SwiperLayout.DEFAULT,
    this.autoplayDelay: kDefaultAutoplayDelayMs, // 自动播放延迟时长,单位ms
    this.autoplayDisableOnInteraction: true, // 交互时是否禁用自动播放
    this.duration: kDefaultAutoplayTransactionDuration, // 动画时间,单位ms
    this.onIndexChanged, // 下标改变的回调
    this.index, // 初始下标
    this.onTap, // 点击轮播的回调
    this.control, // 左右切换指示器
    this.loop: true, // 无缝轮播模式开关
    this.curve: Curves.ease, // 动画曲线
    this.scrollDirection: Axis.horizontal, // 滚动方向
    this.pagination, // 分页指示器
    this.plugins,
    this.physics,
    Key key,
    this.controller,
    this.customLayoutOption,

    this.containerHeight,
    this.containerWidth,
    this.viewportFraction: 1.0, // 轮播区大小
    this.itemHeight,
    this.itemWidth,
    this.outer: false, // 分页指示器是否放在轮播区域外
    this.scale, // 缩放
    this.fade, 
  })
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MAXLZ

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值