diff --git a/lib/models/photo.dart b/lib/models/photo.dart index 394438f06..04e9adae3 100644 --- a/lib/models/photo.dart +++ b/lib/models/photo.dart @@ -57,11 +57,11 @@ class Photo { return photo; } - AssetEntity getAsset() { - return AssetEntity(id: localId); + Future getAsset() { + return AssetEntity.fromId(localId); } - Future getBytes({int quality = 100}) { + Future 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) diff --git a/lib/ui/thumbnail_widget.dart b/lib/ui/thumbnail_widget.dart index fec5085e4..64102a08a 100644 --- a/lib/ui/thumbnail_widget.dart +++ b/lib/ui/thumbnail_widget.dart @@ -52,25 +52,26 @@ class _ThumbnailWidgetState extends State { _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); }); } } diff --git a/lib/ui/zoomable_image.dart b/lib/ui/zoomable_image.dart index 71d808f6a..52473ce84 100644 --- a/lib/ui/zoomable_image.dart +++ b/lib/ui/zoomable_image.dart @@ -139,12 +139,13 @@ class _ZoomableImageState extends State 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 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); + } + }); }); } } diff --git a/pubspec.lock b/pubspec.lock index 0baa661c4..3564edc89 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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: diff --git a/pubspec.yaml b/pubspec.yaml index 2d33e1590..8d9b1c423 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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