save_in_gallery 0.1.3

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 #

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

0.1.3 #

  • Fixed bug that caused photos to not save properly if it was first save after granting gallery access

0.1.2 #

  • Fixed bug that caused too many named albums to be created on iOS
  • Bumped dart minimal version to 2.2.2

0.1.1 #

  • Fixed code warnings
  • Bumped dart minimal version to 2.2.0

0.1.0 #

  • Initial release of save_in_gallery plugin

example/README.md

save_in_gallery_example #

For usage example see main.dart file.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  save_in_gallery: ^0.1.3

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:save_in_gallery/save_in_gallery.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
60
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
80
Learn more about scoring.

We analyzed this package on Aug 21, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19
  • Flutter: 1.7.8+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.2 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test