Enable sharing of remote photos
This commit is contained in:
parent
14a6ed1f2f
commit
b37682d863
3 changed files with 20 additions and 6 deletions
|
@ -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<Uint8List> getOriginalBytes() {
|
||||
return getAsset().originBytes;
|
||||
}
|
||||
|
|
|
@ -60,10 +60,7 @@ class _ZoomableImageState extends State<ZoomableImage> {
|
|||
}
|
||||
|
||||
void _loadNetworkImage() {
|
||||
_imageProvider = Image.network(Configuration.instance.getHttpEndpoint() +
|
||||
"/" +
|
||||
widget.photo.remotePath)
|
||||
.image;
|
||||
_imageProvider = Image.network(widget.photo.getRemoteUrl()).image;
|
||||
}
|
||||
|
||||
void _loadLocalImage(BuildContext context) {
|
||||
|
|
|
@ -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<void> 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<void> share(Photo photo) async {
|
|||
Future<void> shareMultiple(List<Photo> photos) async {
|
||||
final shareContent = Map<String, Uint8List>();
|
||||
for (Photo photo in photos) {
|
||||
shareContent[photo.title] = await photo.getBytes();
|
||||
shareContent[photo.title] = await _getPhotoBytes(photo);
|
||||
}
|
||||
return Share.files("images", shareContent, "*/*");
|
||||
}
|
||||
|
||||
Future<Uint8List> _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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue