Skip to content

Instantly share code, notes, and snippets.

@olumidayy
Created June 29, 2021 11:31
Show Gist options
  • Save olumidayy/50c91e1041c3ceb509e6fb8fe059c1b9 to your computer and use it in GitHub Desktop.
Save olumidayy/50c91e1041c3ceb509e6fb8fe059c1b9 to your computer and use it in GitHub Desktop.
import 'dart:async';
import 'dart:typed_data';
import 'package:flutter/services.dart';
class ImageGallerySaver {
static const MethodChannel _channel =
const MethodChannel('image_gallery_saver');
/// save image to Gallery
/// imageBytes can't null
/// return Map type
/// for example:{"isSuccess":true, "filePath":String?}
static Future saveImage(Uint8List imageBytes,
{int quality = 80,
String name,
String storePath,
bool isReturnImagePathOfIOS = false}) async {
assert(imageBytes != null);
final result =
await _channel.invokeMethod('saveImageToGallery', <String, dynamic>{
'imageBytes': imageBytes,
'quality': quality,
'storePath': storePath,
'name': name,
'isReturnImagePathOfIOS': isReturnImagePathOfIOS
});
return result;
}
/// Save the PNG,JPG,JPEG image or video located at [file] to the local device media gallery.
static Future saveFile(String file, {String storePath, String name, bool isReturnPathOfIOS = false}) async {
assert(file != null);
final result = await _channel.invokeMethod(
'saveFileToGallery', <String, dynamic>{
'file': file,
'name': name,
'storePath': storePath,
'isReturnPathOfIOS': isReturnPathOfIOS
});
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment