diff --git a/ios/Classes/SwiftPhotoGalleryPlugin.swift b/ios/Classes/SwiftPhotoGalleryPlugin.swift index d56084a..67d3d48 100644 --- a/ios/Classes/SwiftPhotoGalleryPlugin.swift +++ b/ios/Classes/SwiftPhotoGalleryPlugin.swift @@ -15,7 +15,8 @@ public class SwiftPhotoGalleryPlugin: NSObject, FlutterPlugin { if(call.method == "listAlbums") { let arguments = call.arguments as! Dictionary 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 @@ -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([ diff --git a/lib/photo_gallery.dart b/lib/photo_gallery.dart index eeb5505..9ca35f6 100644 --- a/lib/photo_gallery.dart +++ b/lib/photo_gallery.dart @@ -25,9 +25,11 @@ class PhotoGallery { /// List all available gallery albums and counts number of items of [MediumType]. static Future> listAlbums({ required MediumType mediumType, + bool? hideIfEmpty = true, }) async { final json = await _channel.invokeMethod('listAlbums', { 'mediumType': mediumTypeToJson(mediumType), + 'hideIfEmpty': hideIfEmpty }); return json.map((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.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.from(bytes); }