part of photogallery; /// Fetches the given album thumbnail from the gallery. class AlbumThumbnailProvider extends ImageProvider { const AlbumThumbnailProvider({ required this.album, this.height, this.width, this.highQuality = false, }); final Album album; final int? height; final int? width; final bool? highQuality; @override ImageStreamCompleter loadBuffer(key, decode) { return MultiFrameImageStreamCompleter( codec: _loadAsync(key, decode), scale: 1.0, informationCollector: () sync* { yield ErrorDescription('Id: ${album.id}'); }, ); } Future _loadAsync(AlbumThumbnailProvider key, DecoderBufferCallback decode) async { assert(key == this); final data = await PhotoGallery.getAlbumThumbnail( albumId: album.id, mediumType: album.mediumType, newest: album.newest, height: height, width: width, highQuality: highQuality, ); ui.ImmutableBuffer buffer; if (data != null) { buffer = await ui.ImmutableBuffer.fromUint8List(Uint8List.fromList(data)); } else { buffer = await ui.ImmutableBuffer.fromAsset("packages/photo_gallery/images/grey.bmp"); } return decode(buffer); } @override Future obtainKey(ImageConfiguration configuration) { return SynchronousFuture(this); } @override bool operator ==(dynamic other) { if (other.runtimeType != runtimeType) return false; final AlbumThumbnailProvider typedOther = other; return album.id == typedOther.album.id; } @override int get hashCode => album.id.hashCode; @override String toString() => '$runtimeType("${album.id}")'; }