搜尋套件、儲存庫與 APP 分類

套件詳情v2.2.1

photo_gallery

一個 Flutter 外掛程式,可從行動裝置原生相簿中取得圖片和影片。

AndroidiOS
近 30 天下載
1640
喜歡數
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,
    ),
)

所屬分類

原始碼儲存庫

使用此套件的專案