flutter實(shí)現(xiàn)輪播圖效果

本文實(shí)例為大家分享了Android九宮格圖片展示的具體代碼,供大家參考,具體內(nèi)容如下

田家庵網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián),田家庵網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為田家庵上1000+提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)營(yíng)銷網(wǎng)站建設(shè)要多少錢(qián),請(qǐng)找那個(gè)售后服務(wù)好的田家庵做網(wǎng)站的公司定做!

1 添加依賴庫(kù)

flutter_swiper: ^1.0.6

2 普通常用 圓點(diǎn)指示器自動(dòng)輪播圖

flutter實(shí)現(xiàn)輪播圖效果

class SwiperViewDefaultPage extends StatefulWidget {
 @override
 State<StatefulWidget> createState() {
  return new SwiperViewDefaultPageState();
 }
}

class SwiperViewDefaultPageState
  extends BaseAppBarPageState<SwiperViewDefaultPage> {
 @override
 String buildInitState() {
  buildBackBar("輪播圖", backIcon: Icons.arrow_back_ios);
  return null;
 }

 @override
 Widget buildWidget(BuildContext context) {
  print("build --");
  return new Column(
   children: <Widget>[
    Padding(
     padding: EdgeInsets.all(10),
    ),
    buildStyle1(),
   ],
  );
 }

 // 分頁(yè)指示器
 buildSwiperPagination() {
  return SwiperPagination(
   //指示器顯示的位置
   alignment: Alignment.bottomCenter, // 位置 Alignment.bottomCenter 底部中間
   // 距離調(diào)整
   margin: const EdgeInsets.fromLTRB(0, 0, 0, 5),
   // 指示器構(gòu)建
   builder: DotSwiperPaginationBuilder(
     // 點(diǎn)之間的間隔
     space: 2,
     // 沒(méi)選中時(shí)的大小
     size: 6,
     // 選中時(shí)的大小
     activeSize: 12,
     // 沒(méi)選中時(shí)的顏色
     color: Colors.black54,
     //選中時(shí)的顏色
     activeColor: Colors.white),
  );
 }

 //banner 圖
 Widget buildStyle1() {
  return Container(
   height: 200.0,
   child: new Swiper(
    // 橫向
    scrollDirection: Axis.horizontal,
    // 布局構(gòu)建
    itemBuilder: (BuildContext context, int index) {
     return new Image.network(
      "http://hbimg.b0.upaiyun.com/a3e592c653ea46adfe1809e35cd7bc58508a6cb94307-aaO54C_fw658",
      fit: BoxFit.fill,
     );
    },
    //條目個(gè)數(shù)
    itemCount: 6,
    // 自動(dòng)翻頁(yè)
    autoplay: true,
    // 分頁(yè)指示
    pagination: buildPlugin(),
    //點(diǎn)擊事件
    onTap: (index) {
     print(" 點(diǎn)擊 " + index.toString());
    },
    // 相鄰子條目視窗比例
    viewportFraction: 1,
    // 布局方式
    //layout: SwiperLayout.STACK,
    // 用戶進(jìn)行操作時(shí)停止自動(dòng)翻頁(yè)
    autoplayDisableOnInteraction: true,
    // 無(wú)線輪播
    loop: true,
    //當(dāng)前條目的縮放比例
    scale: 1,
   ),
  );
 }

 buildPlugin() {
  return SwiperPagination();
 }
}

3 自定圓點(diǎn)分頁(yè)指示器 效果

flutter實(shí)現(xiàn)輪播圖效果

 //自定圓點(diǎn)分頁(yè)指示器
 buildSwiperPagination() {
  // 分頁(yè)指示器
  return SwiperPagination(
   //指示器顯示的位置
   alignment: Alignment.bottomCenter, // 位置 Alignment.bottomCenter 底部中間
   // 距離調(diào)整
   margin: const EdgeInsets.fromLTRB(0, 0, 0, 5),
   // 指示器構(gòu)建
   builder: DotSwiperPaginationBuilder(
     // 點(diǎn)之間的間隔
     space: 2,
     // 沒(méi)選中時(shí)的大小
     size: 6,
     // 選中時(shí)的大小
     activeSize: 12,
     // 沒(méi)選中時(shí)的顏色
     color: Colors.black54,
     //選中時(shí)的顏色
     activeColor: Colors.white),
  );
 }

 //定義輪播圖組件
 Widget buildStyle1() {
  return Container(
   height: 200.0,
   child: new Swiper(
    // 橫向
    scrollDirection: Axis.horizontal,
    // 布局構(gòu)建
    itemBuilder: (BuildContext context, int index) {
     return new Image.network(
      "http://hbimg.b0.upaiyun.com/a3e592c653ea46adfe1809e35cd7bc58508a6cb94307-aaO54C_fw658",
      fit: BoxFit.fill,
     );
    },
    //條目個(gè)數(shù)
    itemCount: 6,
    // 自動(dòng)翻頁(yè)
    autoplay: true,
    // 分頁(yè)指示
    pagination: buildSwiperPagination(),
    //點(diǎn)擊事件
    onTap: (index) {
     print(" 點(diǎn)擊 " + index.toString());
    },
    // 視窗比例
    viewportFraction: 1,
    // 布局方式
    //layout: SwiperLayout.STACK,
    // 用戶進(jìn)行操作時(shí)停止自動(dòng)翻頁(yè)
    autoplayDisableOnInteraction: true,
    // 無(wú)線輪播
    loop: true,
    scale: 1,
   ),
  );
 }

4 自定數(shù)字 分頁(yè)指示器 效果

flutter實(shí)現(xiàn)輪播圖效果

 //自定義分頁(yè)指示器
 buildSwiperPagination() {
  // 分頁(yè)指示器
  return SwiperPagination(
   //指示器顯示的位置
   alignment: Alignment.bottomCenter, // 位置 Alignment.bottomCenter 底部中間
   // 距離調(diào)整
   margin: const EdgeInsets.fromLTRB(0, 0, 0, 5),
   // 指示器構(gòu)建
   builder: FractionPaginationBuilder(
     // 選中時(shí)字體大小
     activeFontSize: 14,
     // 字體大小
     fontSize: 14,
      // 字體顏色
     color: Colors.red,
     //選中時(shí)的顏色
     activeColor: Colors.blue),
  );
 }

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。

網(wǎng)站題目:flutter實(shí)現(xiàn)輪播圖效果
地址分享:http://muchs.cn/article22/gjgcjc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、企業(yè)網(wǎng)站制作、ChatGPT、搜索引擎優(yōu)化外貿(mào)建站、網(wǎng)站內(nèi)鏈

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作