搜索插件、代码仓与 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.

所属分类

源码仓库

使用此插件的项目

暂无相关数据。