Fix image loading on Android Q

This commit is contained in:
Vishnu Mohandas 2020-06-13 22:14:16 +05:30
parent 5254779cc9
commit 81d90da546
5 changed files with 39 additions and 35 deletions

View file

@ -57,11 +57,11 @@ class Photo {
return photo;
}
AssetEntity getAsset() {
return AssetEntity(id: localId);
Future<AssetEntity> getAsset() {
return AssetEntity.fromId(localId);
}
Future<Uint8List> getBytes({int quality = 100}) {
Future<Uint8List> getBytes({int quality = 100}) async {
if (localId == null) {
return HttpClient().getUrl(Uri.parse(getRemoteUrl())).then((request) {
return request.close().then((response) {
@ -69,7 +69,7 @@ class Photo {
});
});
} else {
final originalBytes = getAsset().originBytes;
final originalBytes = (await getAsset()).originBytes;
if (extension(title) == ".HEIC" || quality != 100) {
return originalBytes.then((bytes) {
return FlutterImageCompress.compressWithList(bytes, quality: quality)

View file

@ -52,13 +52,10 @@ class _ThumbnailWidgetState extends State<ThumbnailWidget> {
_imageProvider = Image.memory(cachedSmallThumbnail).image;
_hasLoadedThumbnail = true;
} else {
widget.photo
.getAsset()
widget.photo.getAsset().then((asset) {
asset
.thumbDataWithSize(THUMBNAIL_SMALL_SIZE, THUMBNAIL_SMALL_SIZE)
.catchError((e) {
_logger.warning("Could not load image: ", e);
_encounteredErrorLoadingThumbnail = true;
}).then((data) {
.then((data) {
if (data != null && mounted) {
final imageProvider = Image.memory(data).image;
precacheImage(imageProvider, context).then((value) {
@ -72,6 +69,10 @@ class _ThumbnailWidgetState extends State<ThumbnailWidget> {
}
ThumbnailLruCache.put(widget.photo, THUMBNAIL_SMALL_SIZE, data);
});
}).catchError((e) {
_logger.warning("Could not load image: ", e);
_encounteredErrorLoadingThumbnail = true;
});
}
}
}

View file

@ -139,13 +139,14 @@ class _ZoomableImageState extends State<ZoomableImage>
if (cachedThumbnail != null) {
_onLargeThumbnailLoaded(Image.memory(cachedThumbnail).image, context);
} else {
widget.photo
.getAsset()
widget.photo.getAsset().then((asset) {
asset
.thumbDataWithSize(THUMBNAIL_LARGE_SIZE, THUMBNAIL_LARGE_SIZE)
.then((data) {
_onLargeThumbnailLoaded(Image.memory(data).image, context);
ThumbnailLruCache.put(widget.photo, THUMBNAIL_LARGE_SIZE, data);
});
});
}
}
@ -156,13 +157,15 @@ class _ZoomableImageState extends State<ZoomableImage>
final imageProvider = Image.file(cachedFile).image;
_onFinalImageLoaded(imageProvider, context);
} else {
widget.photo.getAsset().file.then((file) {
widget.photo.getAsset().then((asset) {
asset.file.then((file) {
if (mounted) {
final imageProvider = Image.file(file).image;
_onFinalImageLoaded(imageProvider, context);
ImageLruCache.put(widget.photo, file);
}
});
});
}
}
}

View file

@ -344,7 +344,7 @@ packages:
name: photo_manager
url: "https://pub.dartlang.org"
source: hosted
version: "0.5.1"
version: "0.5.3+1"
photo_view:
dependency: "direct main"
description:

View file

@ -23,7 +23,7 @@ dependencies:
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
photo_manager: ^0.5.1
photo_manager: ^0.5.3+1
provider: ^3.1.0
sqflite: ^1.3.0
path_provider: ^1.6.5