I have app that app display one image to the user. that image I was saved it in MySQL database as a link and image in folder into server. Now I try to make user can share that image to other apps like WhatsApp or Facebook from my app.
I use share_plus 3.0.5 packages to make that:
await Share.shareFiles([//////////////////here/////////////], text: 'Image Shared');
Get image by this code:
Future MakeShare() async {
var response = await http.get(
Uri.parse("https://*********/ImageMakeShare.php?ID=" widget.IDS.toString()),
headers: {"Accept": "application/json"});
setState(() {
var convertDataToJson = json.decode(response.body);
dataImage = convertDataToJson['result'];
if (dataImage != null) {
imageMaine = dataImage[0]['image'];
}}); }
I try to make it like that
await Share.shareFiles([imageMaine ], text: 'Image Shared');
But I get error:
E/flutter (10763): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: PlatformException(https:/*******0ee2e.png (No such file or directory), null, null, null)
Now I need to know how can I make user can share that image to other apps.
Anyone can help me?
CodePudding user response:
You can use my library app_utils which allows you to launch Android and iOS with provided parameters. You can pass your image URI to other applications as an arguments.
eg.
await AppUtils.launchApp( androidPackage: "com.whatsapp", iosUrlScheme: "whatsapp://", params: {"imageUrl": "https://image.png"});
CodePudding user response:
As you can see from the documentation shareFiles()
function expects a list of String pointing to a local path, on the device. You are passing a URI (imageMaine), which is not a local path, so the plugin throws and exception.
If you wanna share a link, than you should use the share()
function.
If you wanna share a file you should first fetch your fine and then send it with the shareFiles function:
final url = Uri.parse("myLink");
final response = await http.get(url);
await File('/yourPath/myItem.png').writeAsBytes(response.bodyBytes);
await Share.shareFiles(['/yourPath/myItem.png'], text: 'Image Shared');