sendEmail function

Future<void> sendEmail({
  1. required String toEmail,
  2. required String subject,
  3. required String body,
})

Sends an email using an external application.

toEmail is the recipient's email address. subject is the subject of the email. body is the body of the email.

Throws an exception if the email launch fails.

Implementation

Future<void> sendEmail({
  required final String toEmail,
  required final String subject,
  required final String body,
}) async {
  final emailLaunchUri = Uri(
    scheme: 'mailto',
    path: toEmail,
    query:
        '${Uri.encodeQueryComponent('subject')}=$subject&${Uri.encodeQueryComponent('body')}=$body',
  );
  if (!await launchUrl(emailLaunchUri)) {
    throw Exception('Could not launch $emailLaunchUri');
  }
}