搜尋套件、儲存庫與 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

原始碼儲存庫

使用此套件的專案

暫無相關資料。