Flutter 发送电子邮件

问题描述 投票:0回答:1

我是 Flutter 的新手。我有一个应用程序,我想打开一个带有预填接收地址的电子邮件应用程序,以便用户可以联系我。我有下面的代码,但我无法以某种方式使其工作。由于某种原因,我没有为应用程序提供午餐。我也不确定它是否也是最好的方法。

 ListTile(
        onTap: () {
          _launchEmail("[email protected]");
        },
        leading: const Icon(Icons.email, size: 24.0, color: Colors.white),
        title: const Text("Contact us"),
        textColor: Colors.white,
        dense: true,
      ),

列表;

void _launchEmail(String toMail) async {
if (Platform.isIOS) {
  var email = 'mailto:$toMail';
  if (await canLaunch(email)) {
    await launch(email);
  } else {
    throw 'LOG (THROW): Email açılamadı. Email: $email';
  }
} else {
  var email =
      'mailto:$toMail?subject=${Uri.encodeFull('tome text here')}&body=${Uri.encodeFull('Mesaj')}';
  if (await canLaunch(email)) {
    await launch(email);
  } else {
    throw 'LOG (THROW): Email açılamadı. Email: $email';
  }
}

}

flutter
1个回答
0
投票

launch
已弃用。使用
launchUrl
代替。

Future<void> launchEmail({required String email, String? subject}) async {
  final url =
      Uri(scheme: 'mailto', path: email, queryParameters: {'subject': subject});

  if (await launchUrl(url)) return;
  throw Exception('Failed to launch url');
}

© www.soinside.com 2019 - 2024. All rights reserved.