使用flutter 插件photo_view

官方使用方法

pubspec.yaml

dependencies:

photo_view: ^0.4.2

$ flutter pub get

2.demo.dart (预览页面)

import 'package:photo_view/photo_view.dart';

import 'package:demo/pages/CRM/PhotoGalleryPage.dart'; //放大页面

……

List photoList = [

{'image': 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1562936046611&di=cdb8d16602b8084e82fae55d27fe1f13&imgtype=0&src=http%3A%2F%2Fimg.juimg.com%2Ftuku%2Fyulantu%2F140828%2F330572-140RR2202190.jpg', 'id': '1'},

{'image': 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1562935809808&di=6051cb3fc647d1a192237ce4070995ba&imgtype=0&src=http%3A%2F%2Fimg1.tplm123.com%2F2008%2F04%2F04%2F3421%2F2310138754037.jpg', 'id': '2'},

{'image': 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1562935791055&di=1e9571a1d2b2fc7674cd6d34262b5d8f&imgtype=0&src=http%3A%2F%2Fhbimg.b0.upaiyun.com%2Fc0befbef04954315be4a5eef7588e4638d39dce69902-Q66s69_fw658', 'id': '3'},

{'image': 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1562935809850&di=f6230a3ab7803ff8b3c8bca4df2972a9&imgtype=0&src=http%3A%2F%2Fbpic.588ku.com%2Felement_origin_min_pic%2F17%2F12%2F11%2Fb1277c307e4c155391b0a80bf430da51.jpg', 'id': '4'},

{'image': 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1562935809811&di=c189a8f1ddf91eb5021273f224c8d6b1&imgtype=0&src=http%3A%2F%2Fku.90sjimg.com%2Felement_origin_min_pic%2F18%2F01%2F24%2F74404e1486735ee978deaea361cc5052.jpg', 'id': '5'},

{'image': 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1562935809807&di=fddfb79b700d15e7484b3c2cb0811487&imgtype=0&src=http%3A%2F%2Fku.90sjimg.com%2Felement_origin_min_pic%2F18%2F01%2F24%2Fc9e953b7367397a2d295bada97da9ae7.jpg', 'id': '6'},

{'image': 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1562935809851&di=0f485a45a89f00641e9837a8fb0dda02&imgtype=0&src=http%3A%2F%2Fwww.juimg.com%2Ftuku%2Fyulantu%2F130904%2F328512-130Z41P34616.jpg', 'id': '7'},

{'image': 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1562935920230&di=2b843e46e19f76da1c139da33b4b7e04&imgtype=0&src=http%3A%2F%2Fimg3.redocn.com%2F20110302%2F20110301_ca853abb590ecc0bd9afmI2pNH9vXbpO.jpg', 'id': '8'},

{'image': 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1562936067656&di=508ea84e0a66dc9c35c31767db326f4a&imgtype=0&src=http%3A%2F%2Fimg1.tplm123.com%2F2008%2F04%2F04%2F3421%2F2309618757442.jpg', 'id': '8'},

];

……

//meeting record photo

Widget _meetingPhotos(BuildContext context) {

return Container(

padding: EdgeInsets.fromLTRB(32, 16, 32, 8),

child: GridView.builder(

shrinkWrap: true, //解决 listview 嵌套报错

physics: NeverScrollableScrollPhysics(), //禁用滑动事件

gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(

//横轴元素个数

crossAxisCount: 3,

//纵轴间距

mainAxisSpacing: 10.0,

//横轴间距

crossAxisSpacing: 10.0,

//子组件宽高长度比例

childAspectRatio: 1.0),

itemBuilder: (BuildContext context, int index) {

return GestureDetector(

onTap: () {

_jumpToGallery(index, photoList);

},

child: Image.network(

photoList[index]['image'],

fit: BoxFit.cover,

),

);

},

itemCount: photoList.length,

),

);

}

//jump to photo gallery

void _jumpToGallery(index, list) {

support.mycJumpPage(

context: context,

page: PhotpGalleryPage(

index: index,

photoList: list,

),

);

}

效果展示

PhotoGalleryPage.dart(全屏滑动展示)

import 'package:flutter/material.dart';

import 'package:photo_view/photo_view.dart';

import 'package:photo_view/photo_view_gallery.dart';

class PhotpGalleryPage extends StatefulWidget {

final List photoList;

final int index;

PhotpGalleryPage({this.photoList, this.index});

@override

_PhotpGalleryPageState createState() => _PhotpGalleryPageState();

}

class _PhotpGalleryPageState extends State{

@override

int currentIndex = 0;

int initialIndex; //初始index

int length;

int title;

@override

void initState() {

currentIndex = widget.index;

initialIndex = widget.index;

length = widget.photoList.length;

title = initialIndex + 1;

super.initState();

}

void onPageChanged(int index) {

setState(() {

currentIndex = index;

title = index + 1;

});

}

Widget build(BuildContext context) {

return Scaffold(

appBar: AppBar(

title: Text('${title} / ${length}'),

centerTitle: true,

),

body: Container(

decoration: BoxDecoration(

color: Colors.black,

),

constraints: BoxConstraints.expand(

height: MediaQuery.of(context).size.height,

),

child: Stack(

alignment: Alignment.bottomRight,

children: [

PhotoViewGallery.builder(

scrollDirection: Axis.horizontal,

scrollPhysics: const BouncingScrollPhysics(),

builder: (BuildContext context, int index) {

return PhotoViewGalleryPageOptions(

imageProvider: NetworkImage(widget.photoList[index]['image']),

initialScale: PhotoViewComputedScale.contained * 1,

heroTag: widget.photoList[index]['id'],

);

},

itemCount: widget.photoList.length,

// loadingChild: widget.loadingChild,

backgroundDecoration: BoxDecoration(

color: Colors.black,

),

pageController: PageController(initialPage: initialIndex), //点进去哪页默认就显示哪一页

onPageChanged: onPageChanged,

),

Container(

padding: const EdgeInsets.all(10.0),

child: Text(

"Image ${currentIndex + 1}",

style: const TextStyle(color: Colors.white, fontSize: 17.0, decoration: null),

),

)

],

)),

);

}

}

效果展示

flutter图片预览_flutter - 图片预览放大滑动(photo_view)相关推荐

  1. flutter图片预览_flutter 图片查看,仿微信

    这个虽然是仿微信的,但是以我自己项目里的要求为主,去掉了一些操作. 这个代码铐去就可以用的. 讲下思路: 手势滑动,不松手前以触摸点的坐标为移动,松手了,按滑动速度,以及滑动范围是否超过一半的屏幕作为 ...

  2. jquery实现上传图片及图片大小验证、图片预览效果代码

    jquery实现上传图片及图片大小验证.图片预览效果代码 jquery实现上传图片及图片大小验证.图片预览效果代码 上传图片验证 */ function submit_upload_picture() ...

  3. 微信小程序实现图片是上传、预览功能

    本文实例讲述了微信小程序实现图片上传.删除和预览功能的方法,分享给大家供大家参考,具体如下: 这里主要介绍一下微信小程序的图片上传图片删除和图片预览 1.可以调用相机也可以从本地相册选择 2.本地实现 ...

  4. android自定义相机预览尺寸,相机在Android中,如何获得最佳尺寸,预览尺寸,图片尺寸,视图尺寸,图像扭曲...

    混合来自OpenGL和 Android相机的视图时图像失真,以便在使用takepicture方法时获取两者的图像.我查了一下,发现相机图片设置为640X480,openGL视图和相机预览都设置为128 ...

  5. 【若依(ruoyi)】表格图片预览功能图片超宽、超高问题

    前言 若依(ruoyi): v4.3 360极速浏览器 12.0.1550.0 (正式版本) (32 位) 操作系统 Windows 10 OS Version 2004 (Build 19041.5 ...

  6. uni-app微信小程序image引入图片;background-image背景图引入图片;小程序预览本地图片;小程序图片过大引入报错;获取本地图片的网络地址;

    uni-app小程序图片使用有image标签和background-image背景图两种方式: 下有获取本地图片的网络地址方式:见第四步 一.方式一:使用image标签引入: uni-app官方ima ...

  7. 微信小程序九宫格预览+单张图片预览

    我们废话不多说直接上效果图 下面是代码 <!-- 单张图片 --> <image style="width:550rpx; height: 600rpx;" sr ...

  8. chrome浏览器不能显示本地图片办法解决(图片预览)

    近期开发项目时有个功能是实现图片预览,但是我将图片路径赋值给img标签的src时,预览的显示是这样的. 唉.我就郁闷了,再仔细一看,浏览器给我加了个路径啊. 这是什么鬼东西啊. 试了一下replace ...

  9. 微信小程序 之wx.previewImage图片预览(多张图片预览)

    wxml部分代码如下: <block wx:for="{{pictures}}" wx:for-item='item' wx:for-index='idx'><i ...

最新文章

  1. 蓝桥杯java第八届第十题--k倍区间
  2. android检测手机网络连接不上,Android WIFI及手机网络连接情况检查
  3. AutoCAD实用小技巧教程。
  4. 调用微信扫码接口实现扫一扫功能
  5. 2.灰尘对计算机的影响,灰尘对电脑有影响不?
  6. 原生html单页应用,web单页应用
  7. TypeError: torch.FloatTensor is not a Module subclass
  8. 测度论中的概率空间,可测空间
  9. 喀纳斯与圣诞之夜(随想)
  10. 超详细CloudCone使用指南
  11. 30岁以后搞Android已经没有前途?复习指南
  12. 字符流何用, 字节流呢
  13. java 计算体积_java 求体积
  14. 蚂蚁金服:AlipayHK上线跨境线下支付新功能
  15. linux安装vlc只能命令行启动,Ubuntu安装多功能的媒体播放器VLC播放器的步骤
  16. 计算机网络课程设计性能优化方案,计算机网络课程设计方案(华北电力大学科技学院).doc...
  17. Windows找不到文件c:program files怎么办?
  18. 怎么用python画圆柱_python绘制圆柱体
  19. ESRI技术认证考试大纲
  20. 树形dp——DOVE爱旅游

热门文章

  1. 基于JAVA+SpringMVC+Mybatis+MYSQL的旅游景点门票售票管理系统
  2. 基于JAVA+SpringMVC+MYSQL的在线音乐网站
  3. 基于JAVA+SpringMVC+Mybatis+MYSQL的洗衣店服务平台管理系统
  4. 基于JAVA+SpringMVC+Mybatis+MYSQL的学生公寓管理系统
  5. ThreadPoolExecutor执行过程分析
  6. 论文阅读(XiangBai——【AAAI2017】TextBoxes_A Fast Text Detector with a Single Deep Neural Network)...
  7. mysql字段A复制到字段B,并替换指定字符
  8. 从零开始学前端:grid布局和音频 --- 今天你学习了吗?(CSS:Day24)
  9. python怎么读取pdf为文本_如何从pdf文件中提取特定文本python
  10. 一文学会Python标准库struct序列化与反序列化