搜索插件、代码仓与 APP 分类

插件详情v1.0.1

photo_gallery_flutter

一个 Flutter 插件,用于从移动原生相册中检索图片和视频。

AndroidiOS
近 30 天下载
12
喜欢数
4
Pub 分数
140

安装插件

flutter pub add photo_gallery_flutter

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个 Flutter 插件,可让 Android 和 iOS 设备上的原生相册中的图片和视频。它提供了一个简单的接口来获取媒体文件,非常适合需要集成相册功能的应用程序,例如照片编辑器、社交媒体平台或媒体管理工具。该插件利用平台特定的 API,确保在两大主流移动操作系统上具有兼容性和性能。

适合场景

  • 在照片应用中集成原生相册访问功能
  • 构建媒体选择界面
  • 从设备图库启用图片/视频上传
  • 使用本地媒体创建照片编辑工具
  • 开发社交媒体应用功能

主要特点

  • 跨平台支持 Android 和 iOS
  • 用于检索媒体文件的简单 API
  • 访问图片和视频的权限
  • 原生性能和可靠性
  • 通过 pub.dev 实现轻松集成

适合对象

  • Flutter 开发人员构建媒体密集型应用
  • 需要相册浏览功能的应用
  • 需要安全原生媒体访问的项目
  • 寻求画廊集成最小设置的开发者

使用建议

  • 需要在两个平台上具备相应的权限
  • 可能在大型媒体库上存在限制
  • 依赖于原生图库 API,这些 API 可能因设备而异
  • 不适用于基于云的媒体检索
  • 画廊UI的自定义选项有限

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Photo Gallery Flutter

pub package

A Flutter plugin that retrieves images and videos from mobile native gallery.

Installation

First, add photo_gallery_flutter as a dependency in your pubspec.yaml file.

iOS

Add the following keys to your Info.plist file, located in <project root>/ios/Runner/Info.plist:

NSPhotoLibraryUsageDescription - describe why your app needs permission for the photo library. This is called Privacy - Photo Library Usage Description in the visual editor.

<key>NSPhotoLibraryUsageDescription</key>
<string>Example usage description</string>
Android

Add the following permissions to your AndroidManifest.xml, located in <project root>/android/app/src/main/AndroidManifest.xml:

<manifest ...>
    <uses-permission
        android:name="android.permission.READ_EXTERNAL_STORAGE"
        android:maxSdkVersion="32" />
    <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
    <uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<manifest/>

Usage

  • Listing albums in the gallery
final List<Album> imageAlbums = await PhotoGalleryFlutter.listAlbums();
final List<Album> videoAlbums = await PhotoGalleryFlutter.listAlbums(
    mediumType: MediumType.video,
    newest: false,
    hideIfEmpty: false,
);
  • Listing media in an album
final MediaPage imagePage = await imageAlbum.listMedia();
final MediaPage videoPage = await imageAlbum.listMedia(
    skip: 5,
    take: 10,
);
final List<Medium> allMedia = [
    ...imagePage.items,
    ...videoPage.items,
];
  • Loading more media in a album
if (!imagePage.isLast) {
    final nextImagePage = await imagePage.nextPage();
    // ...
}
  • Getting a Medium
final Medium medium = await PhotoGalleryFlutter.getMedium(
  mediumId: "10",
  mediumType: MediumType.image
);
  • Getting a file
final File file = await medium.getFile();
final File file = await PhotoGalleryFlutter.getFile(mediumId: mediumId);
  • Getting thumbnail data
final List<int> data = await medium.getThumbnail();
final List<int> data = await PhotoGalleryFlutter.getThumbnail(mediumId: mediumId);

You can also specify thumbnail width and height on Android API 29 or higher; You can also specify thumbnail width, height and whether provider high quality or not on iOS:

final List<int> data = await medium.getThumbnail(
    width: 128,
    height: 128,
    highQuality: true,
);
final List<int> data = await PhotoGalleryFlutter.getThumbnail(
    mediumId: mediumId,
    mediumType: MediumType.image,
    width: 128,
    height: 128,
    highQuality: true,
);
  • Getting album thumbnail data
final List<int> data = await album.getThumbnail();
final List<int> data = await PhotoGalleryFlutter.getAlbumThumbnail(albumId: albumId);

You can also specify thumbnail width and height on Android API 29 or higher; You can also specify thumbnail width, height and whether provider high quality or not on iOS:

final List<int> data = await album.getThumbnail(
    width: 128,
    height: 128,
    highQuality: true,
);
final List<int> data = await PhotoGalleryFlutter.getAlbumThumbnail(
    albumId: albumId,
    mediumType: MediumType.image,
    newest: false,
    width: 128,
    height: 128,
    highQuality: true,
);
  • Displaying medium thumbnail

ThumbnailProvider are available to display thumbnail images (here with the help of dependency transparent_image):

FadeInImage(
    fit: BoxFit.cover,
    placeholder: MemoryImage(kTransparentImage),
    image: ThumbnailProvider(
        mediumId: mediumId,
        mediumType: MediumType.image,
        width: 128,
        height: 128,
        hightQuality: true,
    ),
)

Width and height is only available on Android API 29+ or iOS platform

  • Displaying album thumbnail

AlbumThumbnailProvider are available to display album thumbnail images (here with the help of dependency transparent_image):

FadeInImage(
    fit: BoxFit.cover,
    placeholder: MemoryImage(kTransparentImage),
    image: AlbumThumbnailProvider(
        album: album,
        width: 128,
        height: 128,
        hightQuality: true,
    ),
)

Width and height is only available on Android API 29+ or iOS platform. High quality is only available on iOS platform.

  • Displaying a full size image

You can use PhotoProvider to display the full size image (here with the help of dependency transparent_image):

FadeInImage(
    fit: BoxFit.cover,
    placeholder: MemoryImage(kTransparentImage),
    image: PhotoProvider(
        mediumId: mediumId,
    ),
)
```# photo_gallery_flutter

所属分类

依赖

依赖清单 1 项

  • plugin_platform_interface^2.0.2

源码仓库

使用此插件的项目

暂无相关数据。