Fix image loading on Android Q
This commit is contained in:
parent
5254779cc9
commit
81d90da546
5 changed files with 39 additions and 35 deletions
|
@ -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)
|
||||
|
|
|
@ -52,25 +52,26 @@ class _ThumbnailWidgetState extends State<ThumbnailWidget> {
|
|||
_imageProvider = Image.memory(cachedSmallThumbnail).image;
|
||||
_hasLoadedThumbnail = true;
|
||||
} else {
|
||||
widget.photo
|
||||
.getAsset()
|
||||
.thumbDataWithSize(THUMBNAIL_SMALL_SIZE, THUMBNAIL_SMALL_SIZE)
|
||||
.catchError((e) {
|
||||
widget.photo.getAsset().then((asset) {
|
||||
asset
|
||||
.thumbDataWithSize(THUMBNAIL_SMALL_SIZE, THUMBNAIL_SMALL_SIZE)
|
||||
.then((data) {
|
||||
if (data != null && mounted) {
|
||||
final imageProvider = Image.memory(data).image;
|
||||
precacheImage(imageProvider, context).then((value) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_imageProvider = imageProvider;
|
||||
_hasLoadedThumbnail = true;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
ThumbnailLruCache.put(widget.photo, THUMBNAIL_SMALL_SIZE, data);
|
||||
});
|
||||
}).catchError((e) {
|
||||
_logger.warning("Could not load image: ", e);
|
||||
_encounteredErrorLoadingThumbnail = true;
|
||||
}).then((data) {
|
||||
if (data != null && mounted) {
|
||||
final imageProvider = Image.memory(data).image;
|
||||
precacheImage(imageProvider, context).then((value) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_imageProvider = imageProvider;
|
||||
_hasLoadedThumbnail = true;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
ThumbnailLruCache.put(widget.photo, THUMBNAIL_SMALL_SIZE, data);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -139,12 +139,13 @@ class _ZoomableImageState extends State<ZoomableImage>
|
|||
if (cachedThumbnail != null) {
|
||||
_onLargeThumbnailLoaded(Image.memory(cachedThumbnail).image, context);
|
||||
} else {
|
||||
widget.photo
|
||||
.getAsset()
|
||||
.thumbDataWithSize(THUMBNAIL_LARGE_SIZE, THUMBNAIL_LARGE_SIZE)
|
||||
.then((data) {
|
||||
_onLargeThumbnailLoaded(Image.memory(data).image, context);
|
||||
ThumbnailLruCache.put(widget.photo, THUMBNAIL_LARGE_SIZE, data);
|
||||
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,12 +157,14 @@ class _ZoomableImageState extends State<ZoomableImage>
|
|||
final imageProvider = Image.file(cachedFile).image;
|
||||
_onFinalImageLoaded(imageProvider, context);
|
||||
} else {
|
||||
widget.photo.getAsset().file.then((file) {
|
||||
if (mounted) {
|
||||
final imageProvider = Image.file(file).image;
|
||||
_onFinalImageLoaded(imageProvider, context);
|
||||
ImageLruCache.put(widget.photo, 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);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue