Skip to content

Commit

Permalink
Add album option to dart code
Browse files Browse the repository at this point in the history
  • Loading branch information
natsuk4ze committed Aug 6, 2023
1 parent 52bf5e7 commit 469e055
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
16 changes: 8 additions & 8 deletions lib/src/gal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -19,15 +19,15 @@ 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<void> putVideo(String path) async =>
static Future<void> putVideo(String path, {String? album}) async =>
_voidOrThrow(() async => GalPlatform.instance.putVideo(path));

/// Save a image to the gallery from file [path].
///
/// 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<void> putImage(String path) async =>
static Future<void> putImage(String path, {String? album}) async =>
_voidOrThrow(() async => GalPlatform.instance.putImage(path));

/// Save a image to the gallery from [Uint8List].
Expand All @@ -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<void> putImageBytes(Uint8List bytes) async =>
static Future<void> 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<void> open() async => GalPlatform.instance.open();

/// Check if the app has access permissions.
///
///
/// See: [Permissions](https://github.com/natsuk4ze/gal/wiki/Permissions)
static Future<bool> 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)
Expand Down
21 changes: 15 additions & 6 deletions lib/src/gal_method_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,25 @@ final class MethodChannelGal extends GalPlatform {
final methodChannel = const MethodChannel('gal');

@override
Future<void> putVideo(String path) async =>
methodChannel.invokeMethod<void>('putVideo', {'path': path});
Future<void> putVideo(String path, {String? album}) async =>
methodChannel.invokeMethod<void>('putVideo', {
'path': path,
'album': album,
});

@override
Future<void> putImage(String path) async =>
methodChannel.invokeMethod<void>('putImage', {'path': path});
Future<void> putImage(String path, {String? album}) async =>
methodChannel.invokeMethod<void>('putImage', {
'path': path,
'album': album,
});

@override
Future<void> putImageBytes(Uint8List bytes) async =>
methodChannel.invokeMethod<void>('putImageBytes', {'bytes': bytes});
Future<void> putImageBytes(Uint8List bytes, {String? album}) async =>
methodChannel.invokeMethod<void>('putImageBytes', {
'bytes': bytes,
'album': album,
});

@override
Future<void> open() async => methodChannel.invokeMethod<void>('open');
Expand Down
6 changes: 3 additions & 3 deletions lib/src/gal_platform_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ abstract class GalPlatform extends PlatformInterface {

/// throw [UnimplementedError] when Plugin [MethodChannelGal] did not
/// define [putVideo].
Future<void> putVideo(String path) =>
Future<void> putVideo(String path, {String? album}) =>
throw UnimplementedError('putVideo() has not been implemented.');

/// throw [UnimplementedError] when Plugin [MethodChannelGal] did not
/// define [putImage].
Future<void> putImage(String path) =>
Future<void> putImage(String path, {String? album}) =>
throw UnimplementedError('putImage() has not been implemented.');

/// throw [UnimplementedError] when Plugin [MethodChannelGal] did not
/// define [putImageBytes].
Future<void> putImageBytes(Uint8List bytes) =>
Future<void> putImageBytes(Uint8List bytes, {String? album}) =>
throw UnimplementedError('putImageBytes() has not been implemented.');

/// throw [UnimplementedError] when Plugin [MethodChannelGal] did not
Expand Down

0 comments on commit 469e055

Please sign in to comment.