Fix issue in sharing HEIC files
This commit is contained in:
parent
590b029f3e
commit
f6c3881673
1 changed files with 11 additions and 13 deletions
|
@ -1,33 +1,31 @@
|
|||
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 _getPhotoBytes(photo);
|
||||
final bytes = await photo.getBytes();
|
||||
final filename = _getFilename(photo.title);
|
||||
final ext = extension(photo.title);
|
||||
final shareExt =
|
||||
ext == ".HEIC" ? "jpeg" : ext.substring(1, ext.length).toLowerCase();
|
||||
return Share.file(photo.title, photo.title, bytes, "image/" + shareExt);
|
||||
final shareExt = photo.title.endsWith(".HEIC")
|
||||
? "jpg"
|
||||
: ext.substring(1, ext.length).toLowerCase();
|
||||
return Share.file(filename, filename, bytes, "image/" + shareExt);
|
||||
}
|
||||
|
||||
Future<void> shareMultiple(List<Photo> photos) async {
|
||||
final shareContent = Map<String, Uint8List>();
|
||||
for (Photo photo in photos) {
|
||||
shareContent[photo.title] = await _getPhotoBytes(photo);
|
||||
shareContent[_getFilename(photo.title)] = await photo.getBytes();
|
||||
}
|
||||
return Share.files("images", shareContent, "*/*");
|
||||
}
|
||||
|
||||
Future<Uint8List> _getPhotoBytes(Photo photo) async {
|
||||
if (photo.localId != null) {
|
||||
return await photo.getBytes();
|
||||
String _getFilename(String name) {
|
||||
if (name.endsWith(".HEIC")) {
|
||||
return name.substring(0, name.lastIndexOf(".HEIC")) + ".JPG";
|
||||
} else {
|
||||
var request = await HttpClient().getUrl(Uri.parse(photo.getRemoteUrl()));
|
||||
var response = await request.close();
|
||||
return await consolidateHttpClientResponseBytes(response);
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue