composeEmailHelper function

Future<void> composeEmailHelper({
  1. required String to,
  2. String? subject,
  3. String? body,
})

Open the mail app and compose an email

Implementation

Future<void> composeEmailHelper({
  required String to,
  String? subject,
  String? body,
}) async {
  try {
    debugPrint("[emailUri] $to");
    final Uri emailUri = Uri(
      scheme: 'mailto',
      path: to,
      query: 'body=${Uri.encodeComponent(body ?? '')}&subject=${Uri.encodeComponent(subject ?? '')}',
    );

    if (await canLaunchUrl(emailUri)) {
      await launchUrl(emailUri);
    } else {
      debugPrint("Could not launch email app");
    }
  } catch (e) {
    debugPrint("Error opening email app: $e");
  }
}