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

套件詳情v0.1.3

save_in_gallery

Flutter 插件,可讓您在 Android 和 iOS 的原生相冊中儲存圖片。您可以將圖片儲存至預設相簿或自訂名稱的相簿中。

近 30 天下載
42
喜歡數
21
Pub 分數
40

安裝套件

flutter pub add save_in_gallery

套件介紹

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

一個 Flutter 插件,可讓您在 Android 與 iOS 裝置上將影像儲存至原生相簿。支援儲存至預設相簿或您自訂名稱的相簿,確保與裝置特定的相片儲存系統無縫整合。此外,該插件簡化了產生或修改影像之應用程式的媒體持久化,提供跨平台相容性且設定簡單。非常適合需要使用者友善影像匯出功能的應用。

適用情境

  • 從應用程式中保存生成的圖像
  • 將編輯後的照片匯出到用戶的相冊
  • 建立自訂相冊以實現圖像的有序儲存
  • 與使用者分享應用程式創建的視覺內容
  • 在原生相冊中自動備份圖片

主要特色

  • 跨平台支援(Android 與 iOS)
  • 儲存到預設或命名相冊
  • 用於圖像保存的簡單API
  • 原生圖庫整合
  • 最小設定需求

適合對象

  • 影像編輯應用
  • 照片分享應用
  • 產生視覺內容的應用程式
  • 面向用戶的媒體工具
  • 需要相簿存取權限的開發者

使用建議

  • 需要在兩個平台上具備適當的權限
  • 僅限圖像文件
  • 不支援影片或其他媒體類型
  • 平台特定的行為可能會有所不同
  • 需要手動處理權限請求

原始 README

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

alt text

save_in_gallery

Flutter plugin that allows you to save images in native gallery in both Android and iOS. You can either save them in default album or in named album of your choice.

Installation

For installation details see Installing tab on this page.

Configuration

iOS

To use this plugin in iOS you must add 2 new records to configuration file info.plist located in ios/Runner directory. To do so, open iOS project in Xcode by running open ios/Runner.xcworkspace then right-click on info.plist file in project navigator and click open as > source code. Then add following 2 records at the end of <dict> object:

  • <key>NSPhotoLibraryAddUsageDescription</key> <string>write</string> Where write should be reason why your app requires write access to user's gallery. This is necessary to save images in gallery.
  • <key>NSPhotoLibraryUsageDescription</key> <string>read</string> Where read should be reason why your app requires read access to user's gallery. This is necessary to create and use named albums in gallery.

Be aware that app will ask user's permission to read/write gallery access using standard iOS alerts when you will use methods provided by this plugin. These alerts' appearance can not be changed.

If user declines access, these alerts can not be shown again, instead you must use custom controls to redirect user to Settings app, so they can grant access rights themselves. Methods provided by this plugin will not work unless user provides proper access rights.

Android

This plugin should work out-of-the-box and does not require additional configuration.

Be aware that app will ask user's permission to WRITE_EXTERNAL_STORAGE using standard Android alerts when you will use methods provided by this plugin. These alerts' appearance can not be changed.

If user declines access, these alerts can not be shown again, instead you must use custom controls to redirect user to Settings app, so they can grant access rights themselves. Methods provided by this plugin will not work unless user provides proper access rights.

Examples

Save multiple images from app's assets to default gallery
import  'package:save_in_gallery/save_in_gallery.dart';
final _imageSaver =  ImageSaver();
Future<void> saveAssetImage() async {
	// 1
	final urls =  [
		"assets/image1.jpg",
		"assets/image2.jpg",
		"assets/image3.jpg",
	];
	// 2 
	List<Uint8List> bytesList = [];
	for (final url in urls) {
		final bytes =  await rootBundle.load(url);
		bytesList.add(bytes.buffer.asUint8List());
	}
	// 3
	final res = await _imageSaver.saveImages(
		imageBytes: bytesList
	);
	// 4
}
  1. Prepare list of asset URLs;
  2. Load each image, extract byte data, and map to Uint8List type;
  3. Invoke plugin method to save loaded images;
  4. res variable will hold result of saving operation. If it's true, then everything went as expected and images have been successfully saved. Otherwise something went wrong along the way. Use this variable to provide feedback to user.
Fetch image from web and save it to a named album in gallery
import  'package:save_in_gallery/save_in_gallery.dart';
final _imageSaver =  ImageSaver();
Future<void> saveNetworkImage() async {
	// 1
	final url = "https://some_url/image.png";
	// 2
	final image =  NetworkImage(url);
	final key =  await image.obtainKey(ImageConfiguration());
	final load = image.load(key);
	load.addListener((listener, err) async {
		// 3
		final byteData = await listener.image.toByteData(
			format:  ImageByteFormat.png
		);		
		final bytes = byteData.buffer.asUint8List();
		// 4
		final res =  await _imageSaver.saveImage(
			imageBytes: bytes,
			directoryName:  "dir_name",
		);
		// 5
	});
}
  1. Prepapre URL to image you want to fetch;
  2. Create NetworkImage object with your URL and load it's configuration;
  3. Extract byte data from image;
  4. Invoke plugin method to save fetched image in custom album named dir_name;
  5. res variable will hold result of saving operation. If it's true, then everything went as expected and image have been successfully saved. Otherwise something went wrong along the way. Use this variable to provide feedback to user.

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。