How to only open email app and attach a file?

Viewed 257

I'm trying to only OPEN an email app i.e. Outlook, Gmail, etc. and with an attachment already attached. Ready for the user to write a subject and send it to someone. Again I'm not looking to send it automatically, only open the app with the attachment attached.

So far the only thing I found is this: https://pub.dev/packages/launchers

But I am getting an error message: "No implementation found for method send on channel GitHub.com/sunnyapp/launchers_compose"

Here is my code: I am at a loss. I feel like this should be an easy thing to do. P.S most email openers can open an email app but can't attach attachments. I also know this is for mobile only. Android and iOS.

final Email email = Email(
  body: "This Email was Created by TRS to send an Excel File!",
  subject: "$excelName",
  recipients: [""],
  attachmentPath: fullPath,
);

Iterable<String> platformResponse;

try {
  final results =
  await LaunchService().launch(composeEmailOperation, email);
  print(results);
  platformResponse = results.allAttempts.entries.map((entry) {
    print("Provider = ${entry.key}\nResult = ${entry.value}");
    return "P";
  });
} catch (error, stack) {
  print(error);
  print(stack);
  platformResponse = ["Error: $error"];
}
1 Answers

You can use https://pub.dev/packages/share_plus package:

String filename = './docs/myfile.xlsx'
Share.shareFiles([filename], text: 'This Email was Created by TRS to send an Excel File!');

This opens gmail or whatever app you have with attachment and text but this particular code only works on mobile, not on desktop. I

Related