Flutter Share Email not working on Ios with url_launcher package

75 Views Asked by At

I am using url_launcher plugin in Flutter to Share Email with Subject and its working fine in Android with this package, but nothing happens with Ios or Iphone.

I have crated below function for the same:

 void _launchEmail() async {
    String email = Uri.encodeComponent("");
    String productTitle =
        _catalogStore.summaryInfo?.data?[widget.productIndex].title ?? "";
    String productId =
        _catalogStore.summaryInfo?.data?[widget.productIndex].id ?? "";
    String subject = Uri.encodeComponent(
        "mpo_product".tr() + " - " + productTitle + "($productId)");
    String body = Uri.encodeComponent("");
    Uri mail = Uri.parse("mailto:$email?subject=$subject&body=$body");
    try {
      await launchUrl(mail);
    } catch (e) {
      ToastUtil.show(
          ToastDecorator(
              isSuccess: false,
              msg: "something_went_wrong".tr() + "\n" + e.toString()),
          context,
          gravity: ToastGravity.bottom);
    }
  }

What might be the issue?

2

There are 2 best solutions below

0
On

It was not working in Simulator, Checked in real Ios Device and it worked!

0
On

If you want to use either way please add this key

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>mailto</string>
</array>

and you can send email request by this way also

final Uri params = Uri(
  scheme: 'mailto',
  path: '[email protected]',
  query: 'subject=Subject&body=Body Content', //add subject and body here
);

var url = params.toString();
if (await canLaunch(url)) {
  await launch(url);
} else {
  throw 'Could not launch $url';
}