composeEmailHelper function
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");
}
}