photo_gallery/lib/src/image_providers/album_thumbnail_provider.dart

61 lines
1.5 KiB
Dart
Raw Normal View History

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