diff --git a/lib/models/photo.dart b/lib/models/photo.dart index b9a9e44b7..849c17c8f 100644 --- a/lib/models/photo.dart +++ b/lib/models/photo.dart @@ -4,6 +4,7 @@ import 'package:flutter_image_compress/flutter_image_compress.dart'; import 'package:photo_manager/photo_manager.dart'; import 'package:path/path.dart'; import 'package:logging/logging.dart'; +import 'package:photos/core/configuration.dart'; class Photo { int generatedId; @@ -64,6 +65,10 @@ class Photo { } } + String getRemoteUrl() { + return Configuration.instance.getHttpEndpoint() + "/" + remotePath; + } + Future getOriginalBytes() { return getAsset().originBytes; } diff --git a/lib/ui/zoomable_image.dart b/lib/ui/zoomable_image.dart index 282ee7483..175413c26 100644 --- a/lib/ui/zoomable_image.dart +++ b/lib/ui/zoomable_image.dart @@ -60,10 +60,7 @@ class _ZoomableImageState extends State { } void _loadNetworkImage() { - _imageProvider = Image.network(Configuration.instance.getHttpEndpoint() + - "/" + - widget.photo.remotePath) - .image; + _imageProvider = Image.network(widget.photo.getRemoteUrl()).image; } void _loadLocalImage(BuildContext context) { diff --git a/lib/utils/share_util.dart b/lib/utils/share_util.dart index 5bf24a09d..7459e9989 100644 --- a/lib/utils/share_util.dart +++ b/lib/utils/share_util.dart @@ -1,11 +1,13 @@ +import 'dart:io'; import 'dart:typed_data'; import 'package:esys_flutter_share/esys_flutter_share.dart'; +import 'package:flutter/foundation.dart'; import 'package:photos/models/photo.dart'; import 'package:path/path.dart'; Future share(Photo photo) async { - final bytes = await photo.getBytes(); + final bytes = await _getPhotoBytes(photo); final ext = extension(photo.title); final shareExt = ext == ".HEIC" ? "jpeg" : ext.substring(1, ext.length).toLowerCase(); @@ -15,7 +17,17 @@ Future share(Photo photo) async { Future shareMultiple(List photos) async { final shareContent = Map(); for (Photo photo in photos) { - shareContent[photo.title] = await photo.getBytes(); + shareContent[photo.title] = await _getPhotoBytes(photo); } return Share.files("images", shareContent, "*/*"); } + +Future _getPhotoBytes(Photo photo) async { + if (photo.localId != null) { + return await photo.getBytes(); + } else { + var request = await HttpClient().getUrl(Uri.parse(photo.getRemoteUrl())); + var response = await request.close(); + return await consolidateHttpClientResponseBytes(response); + } +}