7、Flutter banner_view 轮播图的使用

7、Flutter banner_view 轮播图的使用

1、前言

实现轮播图,效果如下:

2、实现

将采用 banner_view 实现:资源库地址

2.1、yaml 引入依赖

在 pubspec.yaml 声明需要引用的库,执行命令 flutter packages get 进行拉取即可使用。

banner_view: "^1.1.2"

 

2.2、代码中引入依赖

 在资源库地址下方,作者提供了 banner_view 的几种展示方式。

import 'package:flutter/material.dart';
import 'package:banner_view/banner_view.dart';import 'Pair.dart';
import 'factory/BannerItemFactory.dart';class BannerViewPage extends StatefulWidget {@override_BannerViewPageState createState() => new _BannerViewPageState();
}class _BannerViewPageState extends State<BannerViewPage> {@overrideWidget build(BuildContext context) {return new Scaffold(body:new Container(child:  new Column(children: <Widget>[new Container(alignment: Alignment.center,height: 200.0,child: this._bannerView0(),padding: EdgeInsets.only(bottom: 10.0),)],),),);}/*** 第一种方式*/BannerView _bannerView0() {// 盛放图片的 ListList<Pair<String, Color>> param = [Pair.create('https://p5.ssl.qhimg.com/dm/456_209_/t01f43c5849ef5f521a.jpg', Colors.red[500]),Pair.create('https://p.ssl.qhimg.com/t0171bb61911ebe8899.jpg', Colors.green[500]),Pair.create('https://p.ssl.qhimg.com/t01ee77978d3a95a3ae.jpg', Colors.blue[500]),];return new BannerView(BannerItemFactory.banners(param),);
//    return new BannerView(
//      BannerItemFactory.banners(param),
//      indicatorMargin: 10.0,
//      indicatorNormal: new Container(
//        width: 5.0,
//        height: 5.0,
//        decoration: new BoxDecoration(
//          color: Colors.green,
//          shape: BoxShape.rectangle,
//        ),
//      ),
//      indicatorSelected: new Container(
//        width: 15.0,
//        height: 5.0,
//        decoration: new BoxDecoration(
//          color: Colors.black,
//          shape: BoxShape.rectangle,
//          borderRadius: new BorderRadius.all(
//            new Radius.circular(5.0),
//          ),
//        ),
//      ),
//      indicatorBuilder: (context, indicator) {
//        Widget cc = new Container(
//          padding: new EdgeInsets.symmetric(horizontal: 20.0,),
//          height: 44.0,
//          width: double.infinity,
//          color: Colors.grey[300],
//          child: indicator,
//        );
//        return new Opacity(
//          opacity: 0.5,
//          child: cc,
//        );
//      },
//    );
  }/*** 第二种方式*/BannerView _bannerView() {var pre = 'https://raw.githubusercontent.com/yangxiaoweihn/Assets/master';List<Pair<String, Color>> param = [Pair.create('https://raw.githubusercontent.com/yangxiaoweihn/Assets/master/cars/car_0.jpg', Colors.red[100]),Pair.create('https://raw.githubusercontent.com/yangxiaoweihn/Assets/master/cartoons/ct_0.jpg', Colors.green[100]),Pair.create('https://raw.githubusercontent.com/yangxiaoweihn/Assets/master/pets/cat_1.jpg', Colors.blue[100]),Pair.create('https://raw.githubusercontent.com/yangxiaoweihn/Assets/master/scenery/s_1.jpg', Colors.yellow[100]),Pair.create('https://raw.githubusercontent.com/yangxiaoweihn/Assets/master/cartoons/ct_1.jpg', Colors.red[100]),
//      Pair.create('$pre/cartoons/ct_1.jpg', Colors.red[100]),
    ];return new BannerView(BannerItemFactory.banners(param),indicatorMargin: 10.0,indicatorNormal: new Container(width: 5.0,height: 5.0,decoration: new BoxDecoration(color: Colors.green,shape: BoxShape.rectangle,),),indicatorSelected: new Container(width: 15.0,height: 5.0,decoration: new BoxDecoration(color: Colors.black,shape: BoxShape.rectangle,borderRadius: new BorderRadius.all(new Radius.circular(5.0),),),),indicatorBuilder: (context, indicator) {Widget cc = new Container(padding: new EdgeInsets.symmetric(horizontal: 20.0,),height: 44.0,width: double.infinity,color: Colors.grey[300],child: indicator,);return new Opacity(opacity: 0.5,child: cc,);},);}
}

 

posted @ 2019-01-26 15:58 niceyoo 阅读(...) 评论(...) 编辑 收藏

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/414595.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Android 人脸实名验证demo——腾讯人脸核身·云智慧眼

可以说比较容易实现&#xff1a;只需要获取BizToken&#xff0c;再起调腾讯SDK即可 1、首先登录腾讯云平台&#xff0c;申请权限&#xff0c;创建应用 腾讯云&#xff1a; https://cloud.tencent.com/ 2、配置应用信息及实名验证流程设置&#xff0c;下载SDK 不过&#xff0c;…

前端学习(2745):重读vue电商网站55之使用 pm2 管理应用

① 在服务器中安装 pm2&#xff1a;npm i pm2 -g ② 启动项目&#xff1a;pm2 start 脚本 --name 自定义名称 ③ 查看运行项目&#xff1a;pm2 ls ④ 重启项目&#xff1a;pm2 restart 自定义名称 ⑤ 停止项目&#xff1a;pm2 stop 自定义名称 ⑥ 删除项目&#xff1a;pm2 dele…

[JSOI 2015] 子集选取

4475: [Jsoi2015]子集选取 Time Limit: 1 Sec Memory Limit: 512 MBSubmit: 363 Solved: 255[Submit][Status][Discuss]Description Input 输入包含一行两个整数N和K&#xff0c;1<N,K<10^9 Output 一行一个整数&#xff0c;表示不同方案数目模1,000,000,007的值。 Sam…

8、D8: Default interface methods are only supported starting with Android N (--min-api 24): void

8、D8: Default interface methods are only supported starting with Android N (--min-api 24): void 1、错误信息 升级完 Android N 后&#xff0c;有些项目运行起来报错信息大致如下&#xff1a; Default interface methods are only supported starting with Android N (…

No field gDefault in class Landroid/app/ActivityManagerNative

启动未注册activity。8.0系统报错如下&#xff1a; 05-06 10:25:31.312 13973-13973/com.bolex.androidhookstartactivity W/System.err: java.lang.NoSuchFieldException: No field gDefault in class Landroid/app/ActivityManagerNative; (declaration of android.app.Acti…

工作242:关于第二个git仓库提交代码

其实第二个仓库 建立的时候直接取进行 push操作就可以完成 原理一样 可以直接对代码地址进行提交

第0周作业2:博客阅读和思考

第0周作业2&#xff1a;博客阅读和思考 拿到题目的第一眼我是抗拒的&#xff0c;因为从大一开始就一直在回答各种关于“你为什么选择这个专业&#xff1f;”&#xff0c;“毕业后有怎样的打算&#xff1f;”&#xff0c;“想找怎样的工作&#xff1f;”这样的问题。可能在自己还…

11、jeecg 笔记之 界面常用整理 - 方便复制粘贴

11、jeecg 笔记之 界面常用整理 - 方便复制粘贴 1、datagrid 操作按钮&#xff08;按钮样式&#xff09; 操作按钮的显示主要依赖于 <t:dgCol title"操作" field"opt" ></t:dgCol> 标签&#xff0c;如果没有该标签&#xff0c;下方即使加入也…

工作243:name报错

name报错就是name的数值报错

Android 图片压缩,Bitmap旋转,bitmap与byte[]之间相互转换,Bitmap与String互转

频繁setImageBitmap引起oom问题解决方法 Glide.with(gsewmimg).load(getCodeBitmap(response.data.skip, R.mipmap.zhifuicon)).into(gsewmimg);压缩前后。图片大小 2.22MB——>200KB 1、图片压缩方法&#xff1a; Bitmap bitmap; byte[] buff; buff Bitmap2Bytes(bitmap…

第八届蓝桥杯-日期问题

标题&#xff1a;日期问题小明正在整理一批历史文献。这些历史文献中出现了很多日期。小明知道这些日期都在1960年1月1日至2059年12月31日。令小明头疼的是&#xff0c;这些日期采用的格式非常不统一&#xff0c;有采用年/月/日的&#xff0c;有采用月/日/年的&#xff0c;还有…

9、Flutter 实现 生成二维码

9、Flutter 实现 生成二维码 1、加入依赖 在 pubspec.yaml 中 dependencies 节点下添加&#xff1a; dependencies: qr_flutter: ^1.1.6 2、引入代码 在需要细线二维码的 dart 类中引入依赖代码包&#xff1a; import package:qr_flutter/qr_flutter.dart; 代码部分 import p…

工作244:根据页面的内容调用

1根据内容接口判断接口数据 2显示不同的内容 3状态管理 <!--首页管理--> <template><div><!--market--><el-card v-if"task1.length!0" style"width: 100%;height: 300px;"><el-carousel :interval"3000"…

Android 换肤demo,轻量快捷接入集成,判断是否夜间模式

true为黑夜模式 //检查当前系统是否已开启暗黑模式 public static boolean getDarkModeStatus(Context context) {int mode context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;return mode Configuration.UI_MODE_NIGHT_YES;} 实现…

Python——使用matplotlib绘制柱状图

Python——使用matplotlib绘制柱状图 1、基本柱状图 首先要安装matplotlib&#xff08;http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.plot&#xff09; 可以使用pip命令直接安装[python] view plaincopy # -*- coding: utf-8 -*- import matplotlib.pyplot a…

了解 yarn 、npm、nodejs

了解 yarn 、npm、nodejs 一、前言 针对即将上线的 jeecg-boot 做一些准备。二、了解系列 1、了解 nodejs Node.js 就是运行在服务端的 JavaScript。Node.js 是一个基于Chrome JavaScript 运行时建立的一个平台。Node.js是一个事件驱动I/O服务端JavaScript环境&#xff0c;基于…

Android 语音播报,语音识别demo

该功能是基于百度智能云实现的根据文字进行语音播报。 1、首先到百度智能云创建语音应用 https://console.bce.baidu.com/ai/ 填写包名创建百度语音应用&#xff0c;获取AppID&#xff0c;API Key&#xff0c;Secret Key 2、导入资源文件。语音jar&#xff0c;assets语音库&am…

jeecg自定义datagrid查询

jeecg自定义datagrid查询 为什么要写这篇文章&#xff1f; 我们了解&#xff0c;使用 jeecg 提供的 CriteriaQuery 查询方式&#xff0c;确实能满足绝大数的需求&#xff0c;但是往往有那么个比较复杂的情况&#xff0c;需要我们直接去写 sql&#xff0c;比如多表查询呀等等等…