ssgf_image_gallery_saver/lib/image_gallery_saver.dart
2025-02-27 10:46:52 +08:00

39 lines
1.1 KiB
Dart
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'dart:async';
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 FutureOr<dynamic> saveImage(Uint8List imageBytes,
{int quality = 80,
String? name,
bool isReturnImagePathOfIOS = false}) async {
final result =
await _channel.invokeMethod('saveImageToGallery', <String, dynamic>{
'imageBytes': imageBytes,
'quality': quality,
'name': name,
'isReturnImagePathOfIOS': isReturnImagePathOfIOS
});
return result;
}
/// Save the PNGJPGJPEG image or video located at [file] to the local device media gallery.
static Future saveFile(String file,
{String? name, bool isReturnPathOfIOS = false}) async {
final result = await _channel.invokeMethod(
'saveFileToGallery', <String, dynamic>{
'file': file,
'name': name,
'isReturnPathOfIOS': isReturnPathOfIOS
});
return result;
}
}