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

插件详情v2.2.1

photo_gallery

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

AndroidiOS
近 30 天下载
2250
喜欢数
162
Pub 分数
150

安装插件

flutter pub add photo_gallery

插件介绍

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

photo_gallery 包是一个 Flutter 插件,旨在访问 Android 和 iOS 设备上的原生相册中的图片和视频。它提供了一个简单的接口来检索媒体文件,使开发者能够将其应用中集成相册浏览和选择功能。该插件利用平台特定的 API,确保在两个操作系统上都能实现兼容性和高性能。对于需要媒体集合功能的应用程序(如照片分享、个人资料图片上传或内容创作工具)来说,这是一个理想的选择。通过 pub add 进行最少的设置,即可无缝集成到现有的 Flutter 项目中。

适合场景

  • 从设备相册中选择图片和视频
  • 个人资料图片上传工作流程
  • 媒体丰富的应用内容创作
  • 照片共享应用程序开发
  • 用户生成内容收集

主要特点

  • Android 和 iOS 的跨平台支持
  • 访问原生相册媒体的简单 API
  • 支持图片和视频
  • 与 flutter pub add 的轻松集成
  • 依赖原生平台 API 以确保可靠性

适合对象

  • 开发媒体密集型 Flutter 应用的开发者
  • 需要相册访问权限以供用户上传的应用
  • 社交媒体或内容创作平台
  • 需要图像/视频选择功能的移动应用
  • 优先考虑原生画廊集成的项目

使用建议

  • Android 和 iOS 需要适当的权限
  • 仅限检索媒体;不支持编辑或裁剪
  • 依赖于原生相册的可用性和系统权限
  • 可能需要对大型媒体文件进行额外处理
  • 不适合高级媒体处理任务

原始 README

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

Photo Gallery

pub package

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

Installation

First, add photo_gallery 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 PhotoGallery.listAlbums();
final List<Album> videoAlbums = await PhotoGallery.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 PhotoGallery.getMedium(
  mediumId: "10",
  mediumType: MediumType.image
);
  • Getting a file
final File file = await medium.getFile();
final File file = await PhotoGallery.getFile(mediumId: mediumId);
  • Getting thumbnail data
final List<int> data = await medium.getThumbnail();
final List<int> data = await PhotoGallery.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 PhotoGallery.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 PhotoGallery.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 PhotoGallery.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,
    ),
)

所属分类

源码仓库

使用此插件的项目