update getting album thumbnail service and AlbumThumbnailProvider to show all grey image when album is empty
This commit is contained in:
parent
f4d3b45070
commit
6a68b22df0
@ -85,7 +85,7 @@ class PhotoGallery {
|
||||
}
|
||||
|
||||
/// Get album thumbnail by album id
|
||||
static Future<List<int>> getAlbumThumbnail({
|
||||
static Future<List<int>?> getAlbumThumbnail({
|
||||
required String albumId,
|
||||
MediumType? mediumType,
|
||||
int? width,
|
||||
@ -99,8 +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);
|
||||
return bytes != null ? new List<int>.from(bytes) : null;
|
||||
}
|
||||
|
||||
/// get medium file by medium id
|
||||
|
@ -17,7 +17,7 @@ class AlbumThumbnailProvider extends ImageProvider<AlbumThumbnailProvider> {
|
||||
final bool? highQuality;
|
||||
|
||||
@override
|
||||
ImageStreamCompleter load(key, decode) {
|
||||
ImageStreamCompleter loadBuffer(key, decode) {
|
||||
return MultiFrameImageStreamCompleter(
|
||||
codec: _loadAsync(key, decode),
|
||||
scale: 1.0,
|
||||
@ -27,17 +27,22 @@ class AlbumThumbnailProvider extends ImageProvider<AlbumThumbnailProvider> {
|
||||
);
|
||||
}
|
||||
|
||||
Future<ui.Codec> _loadAsync(
|
||||
AlbumThumbnailProvider key, DecoderCallback decode) async {
|
||||
Future<ui.Codec> _loadAsync(AlbumThumbnailProvider key, DecoderBufferCallback decode) async {
|
||||
assert(key == this);
|
||||
final bytes = await PhotoGallery.getAlbumThumbnail(
|
||||
final data = await PhotoGallery.getAlbumThumbnail(
|
||||
albumId: albumId,
|
||||
mediumType: mediumType,
|
||||
height: height,
|
||||
width: width,
|
||||
highQuality: highQuality,
|
||||
);
|
||||
return await decode(Uint8List.fromList(bytes));
|
||||
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
|
||||
|
@ -46,7 +46,7 @@ class Album {
|
||||
/// Get thumbnail data for this album.
|
||||
///
|
||||
/// It will display the lastly taken medium thumbnail.
|
||||
Future<List<int>> getThumbnail({
|
||||
Future<List<int>?> getThumbnail({
|
||||
int? width,
|
||||
int? height,
|
||||
bool? highQuality = false,
|
||||
|
@ -70,7 +70,7 @@ void main() {
|
||||
|
||||
test('get album thumbnail', () async {
|
||||
String albumId = "__ALL__";
|
||||
List result = await PhotoGallery.getAlbumThumbnail(albumId: albumId);
|
||||
List? result = await PhotoGallery.getAlbumThumbnail(albumId: albumId);
|
||||
List expected = Generator.generateMockAlbumThumbnail(albumId: albumId);
|
||||
expect(result, expected);
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user