composeNewEmailInMailApp static method
Future<OpenMailAppResult>
composeNewEmailInMailApp({
- String nativePickerTitle = '',
- required EmailContent emailContent,
Allows you to open a mail application installed on the user's device
and start composing a new email with the contents in emailContent
.
EmailContent Provides content for the email you're composing String (android) sets the title of the native picker. throws an Exception if you're launching from an unsupported platform.
Implementation
static Future<OpenMailAppResult> composeNewEmailInMailApp({
String nativePickerTitle = '',
required EmailContent emailContent,
}) async {
if (_isAndroid) {
final result = await _channel.invokeMethod<bool>(
'composeNewEmailInMailApp',
<String, String>{
'nativePickerTitle': nativePickerTitle,
'emailContent': emailContent.toJson(),
},
) ??
false;
return OpenMailAppResult(didOpen: result);
} else if (_isIOS) {
List<MailApp> installedApps = await _getIosMailApps();
if (installedApps.length == 1) {
bool result = false;
String? launchScheme =
installedApps.first.composeLaunchScheme(emailContent);
if (launchScheme != null) {
result = await launch(
launchScheme,
forceSafariVC: false,
);
}
return OpenMailAppResult(didOpen: result);
} else {
// This isn't ideal since you can't do anything with this...
// Need to adapt the flow with that popup to also allow to pass emailcontent there.
return OpenMailAppResult(didOpen: false, options: installedApps);
}
} else {
throw Exception('Platform currently not supported.');
}
}