Skip to content

Commit

Permalink
Add toAlbum option in dart permission-handlings
Browse files Browse the repository at this point in the history
  • Loading branch information
natsuk4ze committed Aug 8, 2023
1 parent 5d78339 commit ddfe01f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
7 changes: 4 additions & 3 deletions lib/src/gal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,16 @@ final class Gal {
/// Check if the app has access permissions.
///
/// See: [Permissions](https://github.com/natsuk4ze/gal/wiki/Permissions)
static Future<bool> hasAccess() async => GalPlatform.instance.hasAccess();
static Future<bool> hasAccess({bool toAlbum = false}) async =>
GalPlatform.instance.hasAccess(toAlbum: toAlbum);

/// 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)
static Future<bool> requestAccess() async =>
GalPlatform.instance.requestAccess();
static Future<bool> requestAccess({bool toAlbum = false}) async =>
GalPlatform.instance.requestAccess(toAlbum: toAlbum);

static Future<void> _voidOrThrow(Future<void> Function() cb) async {
try {
Expand Down
12 changes: 8 additions & 4 deletions lib/src/gal_method_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,18 @@ final class MethodChannelGal extends GalPlatform {
Future<void> open() async => methodChannel.invokeMethod<void>('open');

@override
Future<bool> hasAccess() async {
final hasAccess = await methodChannel.invokeMethod<bool>('hasAccess');
Future<bool> hasAccess({bool toAlbum = false}) async {
final hasAccess = await methodChannel.invokeMethod<bool>('hasAccess', {
'toAlbum': toAlbum,
});
return hasAccess ?? false;
}

@override
Future<bool> requestAccess() async {
final granted = await methodChannel.invokeMethod<bool>('requestAccess');
Future<bool> requestAccess({bool toAlbum = false}) async {
final granted = await methodChannel.invokeMethod<bool>('requestAccess', {
'toAlbum': toAlbum,
});
return granted ?? false;
}
}
4 changes: 2 additions & 2 deletions lib/src/gal_platform_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ abstract class GalPlatform extends PlatformInterface {

/// throw [UnimplementedError] when Plugin [MethodChannelGal] did not
/// define [hasAccess].
Future<bool> hasAccess() =>
Future<bool> hasAccess({bool toAlbum = false}) =>
throw UnimplementedError('hasAccess() has not been implemented.');

/// throw [UnimplementedError] when Plugin [MethodChannelGal] did not
/// define [requestAccess].
Future<bool> requestAccess() =>
Future<bool> requestAccess({bool toAlbum = false}) =>
throw UnimplementedError('requestAccess() has not been implemented.');
}

0 comments on commit ddfe01f

Please sign in to comment.