From 469e055481d72bf9fbb8a2363976b1f2d11f98a2 Mon Sep 17 00:00:00 2001 From: yuoohama Date: Sun, 6 Aug 2023 11:13:14 +0900 Subject: [PATCH] Add album option to dart code --- lib/src/gal.dart | 16 ++++++++-------- lib/src/gal_method_channel.dart | 21 +++++++++++++++------ lib/src/gal_platform_interface.dart | 6 +++--- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/lib/src/gal.dart b/lib/src/gal.dart index 586a4cda..e66032dd 100644 --- a/lib/src/gal.dart +++ b/lib/src/gal.dart @@ -5,8 +5,8 @@ import 'package:gal/src/gal_exception.dart'; import 'gal_platform_interface.dart'; /// A main class of gal. -/// -/// Note: For Android emulators with API level 23 or lower will save media +/// +/// Note: For Android emulators with API level 23 or lower will save media /// on the SD card. Therefore, be sure to set the SD card. You can ignore /// this for real devices. /// See: [wiki](https://github.com/natsuk4ze/gal/wiki) @@ -19,7 +19,7 @@ final class Gal { /// Throws an [GalException] If you do not have access premission or /// if an error occurs during saving. /// See: [Formats](https://github.com/natsuk4ze/gal/wiki/Formats) - static Future putVideo(String path) async => + static Future putVideo(String path, {String? album}) async => _voidOrThrow(() async => GalPlatform.instance.putVideo(path)); /// Save a image to the gallery from file [path]. @@ -27,7 +27,7 @@ final class Gal { /// Throws an [GalException] If you do not have access premission or /// if an error occurs during saving. /// See: [Formats](https://github.com/natsuk4ze/gal/wiki/Formats) - static Future putImage(String path) async => + static Future putImage(String path, {String? album}) async => _voidOrThrow(() async => GalPlatform.instance.putImage(path)); /// Save a image to the gallery from [Uint8List]. @@ -36,21 +36,21 @@ final class Gal { /// Throws an [GalException] If you do not have access premission or /// if an error occurs during saving. /// See: [Formats](https://github.com/natsuk4ze/gal/wiki/Formats) - static Future putImageBytes(Uint8List bytes) async => + static Future putImageBytes(Uint8List bytes, {String? album}) async => _voidOrThrow(() async => GalPlatform.instance.putImageBytes(bytes)); /// Open gallery app. - /// + /// /// If there are multiple gallery apps, App selection sheet may be displayed. static Future open() async => GalPlatform.instance.open(); /// Check if the app has access permissions. - /// + /// /// See: [Permissions](https://github.com/natsuk4ze/gal/wiki/Permissions) static Future hasAccess() async => GalPlatform.instance.hasAccess(); /// Request access permissions. - /// + /// /// Returns [true] if access is granted, [false] if denied. /// If access was already granted, the dialog is not displayed and returns true. /// See: [Permissions](https://github.com/natsuk4ze/gal/wiki/Permissions) diff --git a/lib/src/gal_method_channel.dart b/lib/src/gal_method_channel.dart index bd8af82b..f576849b 100644 --- a/lib/src/gal_method_channel.dart +++ b/lib/src/gal_method_channel.dart @@ -10,16 +10,25 @@ final class MethodChannelGal extends GalPlatform { final methodChannel = const MethodChannel('gal'); @override - Future putVideo(String path) async => - methodChannel.invokeMethod('putVideo', {'path': path}); + Future putVideo(String path, {String? album}) async => + methodChannel.invokeMethod('putVideo', { + 'path': path, + 'album': album, + }); @override - Future putImage(String path) async => - methodChannel.invokeMethod('putImage', {'path': path}); + Future putImage(String path, {String? album}) async => + methodChannel.invokeMethod('putImage', { + 'path': path, + 'album': album, + }); @override - Future putImageBytes(Uint8List bytes) async => - methodChannel.invokeMethod('putImageBytes', {'bytes': bytes}); + Future putImageBytes(Uint8List bytes, {String? album}) async => + methodChannel.invokeMethod('putImageBytes', { + 'bytes': bytes, + 'album': album, + }); @override Future open() async => methodChannel.invokeMethod('open'); diff --git a/lib/src/gal_platform_interface.dart b/lib/src/gal_platform_interface.dart index f24ff520..145b8cf8 100644 --- a/lib/src/gal_platform_interface.dart +++ b/lib/src/gal_platform_interface.dart @@ -18,17 +18,17 @@ abstract class GalPlatform extends PlatformInterface { /// throw [UnimplementedError] when Plugin [MethodChannelGal] did not /// define [putVideo]. - Future putVideo(String path) => + Future putVideo(String path, {String? album}) => throw UnimplementedError('putVideo() has not been implemented.'); /// throw [UnimplementedError] when Plugin [MethodChannelGal] did not /// define [putImage]. - Future putImage(String path) => + Future putImage(String path, {String? album}) => throw UnimplementedError('putImage() has not been implemented.'); /// throw [UnimplementedError] when Plugin [MethodChannelGal] did not /// define [putImageBytes]. - Future putImageBytes(Uint8List bytes) => + Future putImageBytes(Uint8List bytes, {String? album}) => throw UnimplementedError('putImageBytes() has not been implemented.'); /// throw [UnimplementedError] when Plugin [MethodChannelGal] did not