Flutter 照片视图

一个简单的 Flutter 可缩放图片组件

PhotoView 在全屏展示场景中非常有用。

解析图片提供者并显示结果,支持手势,如捏合缩放和平移。

安装

photo_view 添加到您的 pubspec.yaml 文件中作为依赖项。

导入 Photo View

import 'package:photo_view/photo_view.dart';

示例代码

给定一个 ImageProvider imageProvider(例如 AssetImageNetworkImage

@override
Widget build(BuildContext context) {
  return new Container(
    child: new PhotoView(
      imageProvider: AssetImage("assets/large-image.jpg"),
      minScale: PhotoViewComputedScale.contained * 0.8,
      maxScale: 4.0,
    );
  );
}

内联使用

如果您希望 PhotoView 在与屏幕大小不同的容器中缩放图像,请改用 PhotoViewInline

@override
Widget build(BuildContext context) {
  return new Container(
    child: new PhotoViewInline(
      imageProvider: AssetImage("assets/large-image.jpg"),
      minScale: PhotoViewComputedScale.contained * 0.8,
      maxScale: 4.0,
    );
  );
}

API

有关如何使用 Photo View 的更多信息,请查看 API 文档

截图

大图 小图 动画 GIF
In action In action In action
有限缩放 内联 Hero 动画
In action In action In action

待办事项

  • [x] 双击缩放
  • [x] 捏合缩放
  • [x] 遵守屏幕和图像边界
  • [x] 缩小图像时居中
  • [x] 添加图像缩放限制(minScalemaxScale
  • [x] 支持 GIF
  • [ ] 多图支持(画廊模式)
  • [ ] 旋转手势旋转图像(进行中

欢迎贡献代码?。

GitHub

https://github.com/renancaraujo/photo_view