'How to share files with a different extension

As I said in the title, I'm trying to share files converting an image file to PNG format. I have tried to use the packages share_plus and social_share. I have this code:

img.Image? image = img.decodeImage(File(imageXFile.path).readAsBytesSync());

final imageFile = File('${appDir.path}/$fileName.png');
imageFile.writeAsBytesSync(img.encodePng(image));

setState(() {
  _items.add(new Item(fileName, imageFile));
});

I'm trying to share the file using imageFile.path. I also tried including the image/png as mimeType, but still get the original file name and extension when I share the file.

UPDATE: I tried to find a solution for this bug, but nothing yet. It appears that is not a share_plus issue, image package neither. I printed the uri and mimeType in share_plus Kotlin code before start the activity and I got the right infos (png mimetype and the .png extension). I don't know how to proceed now.
My last (and unsuccessful) test was this:

final XFile? imageXFile = await _picker.pickImage(source: ImageSource.gallery);
final imageFile = File('${appDir.path}/$fileName.png');
imageFile.writeAsBytesSync(await imageXFile.readAsBytes());
Share.shareFiles([imageFile.path], mimeTypes: ["image/png"]);

I tried to pick a PNG image, save it and share it immediately, but still share the image as JPG.

OBS: While I was writing this update, I noticed that when I share with Telegram (as uncompressed file), it will be sent as JPG. When I share with Outlook, it is attached as PNG (with the name and extension that I want to).



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source