part of photogallery; /// Fetches the given album thumbnail from the gallery. class AlbumThumbnailProvider extends ImageProvider { const AlbumThumbnailProvider({ required this.albumId, this.mediumType, this.height, this.width, this.highQuality = false, }); final String albumId; final MediumType? mediumType; final int? height; final int? width; final bool? highQuality; @override ImageStreamCompleter load(key, decode) { return MultiFrameImageStreamCompleter( codec: _loadAsync(key, decode), scale: 1.0, informationCollector: () sync* { yield ErrorDescription('Id: $albumId'); }, ); } Future _loadAsync( AlbumThumbnailProvider key, DecoderCallback decode) async { assert(key == this); final bytes = await PhotoGallery.getAlbumThumbnail( albumId: albumId, mediumType: mediumType, height: height, width: width, highQuality: highQuality, ); return await decode(Uint8List.fromList(bytes)); } @override Future obtainKey(ImageConfiguration configuration) { return SynchronousFuture(this); } @override bool operator ==(dynamic other) { if (other.runtimeType != runtimeType) return false; final AlbumThumbnailProvider typedOther = other; return albumId == typedOther.albumId; } @override int get hashCode => albumId.hashCode; @override String toString() => '$runtimeType("$albumId")'; }