add optional "hideIfEmpty" parameter in "listAlbums" API to show empty albums, only available on iOS platform
This commit is contained in:
parent
270432154d
commit
ea75f18cfe
@ -15,7 +15,8 @@ public class SwiftPhotoGalleryPlugin: NSObject, FlutterPlugin {
|
||||
if(call.method == "listAlbums") {
|
||||
let arguments = call.arguments as! Dictionary<String, AnyObject>
|
||||
let mediumType = arguments["mediumType"] as! String
|
||||
result(listAlbums(mediumType: mediumType))
|
||||
let hideIfEmpty = arguments["hideIfEmpty"] as? Bool
|
||||
result(listAlbums(mediumType: mediumType, hideIfEmpty: hideIfEmpty))
|
||||
}
|
||||
else if(call.method == "listMedia") {
|
||||
let arguments = call.arguments as! Dictionary<String, AnyObject>
|
||||
@ -89,7 +90,7 @@ public class SwiftPhotoGalleryPlugin: NSObject, FlutterPlugin {
|
||||
|
||||
private var assetCollections : [PHAssetCollection] = []
|
||||
|
||||
private func listAlbums(mediumType: String) -> [NSDictionary] {
|
||||
private func listAlbums(mediumType: String, hideIfEmpty: Bool? = true) -> [NSDictionary] {
|
||||
self.assetCollections = []
|
||||
let fetchOptions = PHFetchOptions()
|
||||
var total = 0
|
||||
@ -142,13 +143,13 @@ public class SwiftPhotoGalleryPlugin: NSObject, FlutterPlugin {
|
||||
// Smart Albums.
|
||||
processPHAssetCollections(
|
||||
fetchResult: PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .albumRegular, options: fetchOptions),
|
||||
hideIfEmpty: true
|
||||
hideIfEmpty: hideIfEmpty ?? true
|
||||
)
|
||||
|
||||
// User-created collections.
|
||||
processPHCollections(
|
||||
fetchResult: PHAssetCollection.fetchTopLevelUserCollections(with: fetchOptions),
|
||||
hideIfEmpty: true
|
||||
hideIfEmpty: hideIfEmpty ?? true
|
||||
)
|
||||
|
||||
albums.insert([
|
||||
|
@ -25,9 +25,11 @@ class PhotoGallery {
|
||||
/// List all available gallery albums and counts number of items of [MediumType].
|
||||
static Future<List<Album>> listAlbums({
|
||||
required MediumType mediumType,
|
||||
bool? hideIfEmpty = true,
|
||||
}) async {
|
||||
final json = await _channel.invokeMethod('listAlbums', {
|
||||
'mediumType': mediumTypeToJson(mediumType),
|
||||
'hideIfEmpty': hideIfEmpty
|
||||
});
|
||||
return json.map<Album>((x) => Album.fromJson(x)).toList();
|
||||
}
|
||||
@ -78,6 +80,7 @@ class PhotoGallery {
|
||||
'height': height,
|
||||
'highQuality': highQuality,
|
||||
});
|
||||
if (bytes == null) throw "Failed to fetch thumbnail of medium $mediumId";
|
||||
return new List<int>.from(bytes);
|
||||
}
|
||||
|
||||
@ -96,6 +99,7 @@ class PhotoGallery {
|
||||
'height': height,
|
||||
'highQuality': highQuality,
|
||||
});
|
||||
if (bytes == null) throw "Failed to fetch thumbnail of album $albumId";
|
||||
return new List<int>.from(bytes);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user