openMailApp static method

Future<OpenMailAppResult> openMailApp({
  1. String nativePickerTitle = '',
})

Attempts to open an email app installed on the device.

Android: Will open mail app or show native picker if multiple.

iOS: Will open mail app if single installed mail app is found. If multiple are found will return a OpenMailAppResult that contains list of MailApps. This can be used along with MailAppPickerDialog to allow the user to pick the mail app they want to open.

Also see openSpecificMailApp and getMailApps for other use cases.

Android: nativePickerTitle will set the title of the native picker.

Implementation

static Future<OpenMailAppResult> openMailApp({
  String nativePickerTitle = '',
}) async {
  if (_isAndroid) {
    final result = await _channel.invokeMethod<bool>(
          'openMailApp',
          <String, dynamic>{'nativePickerTitle': nativePickerTitle},
        ) ??
        false;
    return OpenMailAppResult(didOpen: result);
  } else if (_isIOS) {
    final apps = await _getIosMailApps();
    if (apps.length == 1) {
      final result = await launch(
        apps.first.iosLaunchScheme,
        forceSafariVC: false,
      );
      return OpenMailAppResult(didOpen: result);
    } else {
      return OpenMailAppResult(didOpen: false, options: apps);
    }
  } else {
    throw Exception('Platform not supported');
  }
}