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

套件詳情v0.1.5

media_gallery

一個列出原生相簿項目之 Flutter 插件。

近 30 天下載
36
喜歡數
31
Pub 分數
30

安裝套件

flutter pub add media_gallery

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

media_gallery 套件是一個 Flutter 插件,可存取原生裝置相簿項目,讓使用者能夠瀏覽並從裝置的本機媒體儲存空間中選擇圖片與影片。它提供簡單介面來取得帶有檔案路徑、時間戳記與尺寸等元資料的媒體檔案。此套件專為與 Flutter 應用程式無縫整合而設計,支援 Android 與 iOS 的平台特定實作。對於需要媒體選取功能的應用程式(如照片分享、個人頭像上傳或內容創作工具)極為適合。它依賴原生 API 以確保效能與相容性。

適用情境

  • 從設備圖庫中選擇圖片和影片
  • 個人檔案圖片上傳流程
  • 媒體豐富的應用內容創作
  • 在Flutter應用中瀏覽照片相冊
  • 將原生媒體選擇器整合到Flutter UI

主要特色

  • 訪問原生設備媒體檔案
  • 同時支援圖片和影片
  • 檢索媒體元數據(路徑、時間戳、大小)
  • 跨平台相容性(Android/iOS)
  • 用於列出和篩選媒體的簡單 API

適合對象

  • 需要媒體選擇的Flutter應用
  • 社群媒體或照片分享平台
  • 內容創作工具
  • 包含使用者產生的媒體上傳應用
  • 開發自訂媒體選擇器的開發者

使用建議

  • 需要適當的權限(相機和儲存)
  • 僅限原生相簿;不支援雲端媒體
  • 平台特定的行為可能有所差異
  • 無內建UI元件;需自訂實作
  • 大型媒體資料庫可能需要額外的處理

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

Media Gallery plugin for Flutter

pub package

A Flutter plugin that lists native gallery items.

Installation

First, add media_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:

<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:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

You should also manage those permissions (for example thanks to the permission_handler plugin). You can see an example for more details.

Usage
Listing media collections
final List<MediaCollection> collections = await MediaGallery.listMediaCollections(
    mediaTypes: [MediaType.image, MediaType.video],
);
Listing medias in a collection
final MediaPage imagePage = await collection.getMedias(
    mediaType: MediaType.image,
    take: 500,
);
final MediaPage videoPage = await collection.getMedias(
    mediaType: MediaType.video,
    take: 500,
);
final List<Media> allMedias = [
    ...imageRange.items,
    ...videoRange.items,
]
..sort((x, y) => y.creationDate.compareTo(x.creationDate));
Loading more medias in a collection
if (!imagePage.isLast) {
    final nextImagePage = await imagePage.nextPage();
    // ...
}
Getting a file
final File file = await media.getFile();
Getting thumbnail data
final List<int> data = await media.getThumbnail();
Displaying thumbnails

MediaThumbnailProvider, MediaCollectionThumbnailProvider are available to display thumbnail images (here with the help of transparent_image) :

FadeInImage(
    fit: BoxFit.cover,
    placeholder: MemoryImage(kTransparentImage),
    image: MediaThumbnailProvider(
        media: media,
    ),
)
Displaying medias

You can use MediaImageProvider to display an image (here with the help of transparent_image):

FadeInImage(
    fit: BoxFit.cover,
    placeholder: MemoryImage(kTransparentImage),
    image: MediaImageProvider(
        media: media,
    ),
)

To display a video, you can use video_player.

Image/Video picker

picker

You can build a gallery picker easily with this package.

See the example for more details.

所屬分類

原始碼儲存庫

使用此套件的專案