update getting album thumbnail and album thumbnail provider
This commit is contained in:
parent
ce01bdb79e
commit
8e6ac397a7
@ -84,7 +84,7 @@ class PhotoGallery {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get album thumbnail by album id
|
/// Get album thumbnail by album id
|
||||||
static Future<List<int>?> getAlbumThumbnail({
|
static Future<List<int>> getAlbumThumbnail({
|
||||||
required String albumId,
|
required String albumId,
|
||||||
MediumType? mediumType,
|
MediumType? mediumType,
|
||||||
bool newest = true,
|
bool newest = true,
|
||||||
@ -100,7 +100,8 @@ class PhotoGallery {
|
|||||||
'height': height,
|
'height': height,
|
||||||
'highQuality': highQuality,
|
'highQuality': highQuality,
|
||||||
});
|
});
|
||||||
return bytes != null ? new List<int>.from(bytes) : null;
|
if (bytes == null) throw "Failed to fetch thumbnail of album $albumId";
|
||||||
|
return new List<int>.from(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get medium file by medium id
|
/// get medium file by medium id
|
||||||
|
@ -27,6 +27,8 @@ class AlbumThumbnailProvider extends ImageProvider<AlbumThumbnailProvider> {
|
|||||||
|
|
||||||
Future<ui.Codec> _loadAsync(AlbumThumbnailProvider key, ImageDecoderCallback decode) async {
|
Future<ui.Codec> _loadAsync(AlbumThumbnailProvider key, ImageDecoderCallback decode) async {
|
||||||
assert(key == this);
|
assert(key == this);
|
||||||
|
late ui.ImmutableBuffer buffer;
|
||||||
|
try {
|
||||||
final data = await PhotoGallery.getAlbumThumbnail(
|
final data = await PhotoGallery.getAlbumThumbnail(
|
||||||
albumId: album.id,
|
albumId: album.id,
|
||||||
mediumType: album.mediumType,
|
mediumType: album.mediumType,
|
||||||
@ -35,10 +37,8 @@ class AlbumThumbnailProvider extends ImageProvider<AlbumThumbnailProvider> {
|
|||||||
width: width,
|
width: width,
|
||||||
highQuality: highQuality,
|
highQuality: highQuality,
|
||||||
);
|
);
|
||||||
ui.ImmutableBuffer buffer;
|
|
||||||
if (data != null) {
|
|
||||||
buffer = await ui.ImmutableBuffer.fromUint8List(Uint8List.fromList(data));
|
buffer = await ui.ImmutableBuffer.fromUint8List(Uint8List.fromList(data));
|
||||||
} else {
|
} catch (e) {
|
||||||
buffer = await ui.ImmutableBuffer.fromAsset("packages/photo_gallery/images/grey.bmp");
|
buffer = await ui.ImmutableBuffer.fromAsset("packages/photo_gallery/images/grey.bmp");
|
||||||
}
|
}
|
||||||
return decode(buffer);
|
return decode(buffer);
|
||||||
|
@ -49,7 +49,7 @@ class Album {
|
|||||||
/// Get thumbnail data for this album.
|
/// Get thumbnail data for this album.
|
||||||
///
|
///
|
||||||
/// It will display the lastly taken medium thumbnail.
|
/// It will display the lastly taken medium thumbnail.
|
||||||
Future<List<int>?> getThumbnail({
|
Future<List<int>> getThumbnail({
|
||||||
int? width,
|
int? width,
|
||||||
int? height,
|
int? height,
|
||||||
bool? highQuality = false,
|
bool? highQuality = false,
|
||||||
|
@ -74,7 +74,7 @@ void main() {
|
|||||||
|
|
||||||
test('get album thumbnail', () async {
|
test('get album thumbnail', () async {
|
||||||
String albumId = "__ALL__";
|
String albumId = "__ALL__";
|
||||||
List? result = await PhotoGallery.getAlbumThumbnail(albumId: albumId);
|
List result = await PhotoGallery.getAlbumThumbnail(albumId: albumId);
|
||||||
List expected = Generator.generateMockAlbumThumbnail(albumId: albumId);
|
List expected = Generator.generateMockAlbumThumbnail(albumId: albumId);
|
||||||
expect(result, expected);
|
expect(result, expected);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user