当我通过表单发送电子邮件时出现此错误。
未处理的异常:PlatformException(不可用,无法使用反邮件应用程序,为空)
class _MyAppState extends State<MyApp> {
List<String> attachment = <String>[];
TextEditingController _subjectController =
TextEditingController(text: 'ct');
TextEditingController _bodyController = TextEditingController(
text: ''' a
''');
final GlobalKey<ScaffoldState> _scafoldKey = GlobalKey<ScaffoldState>();
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> send() async {
// Platform messages may fail, so we use a try/catch PlatformException.
final MailOptions mailOptions = MailOptions(
body: 'Ro',
subject: 'the Email Subject',
recipients: ['rodrigo@houlak.com'],
isHTML: true,
attachments: [ 'path/to/image.png', ],
);
await FlutterMailer.send(mailOptions);
String platformResponse;
try {
await FlutterMailer.send(mailOptions);
platformResponse = 'success';
} catch (error) {
platformResponse = error.toString();
}
if (!mounted) return;
_scafoldKey.currentState.showSnackBar(SnackBar(
content: Text(platformResponse),
));
}
答案 0 :(得分:2)
在 AndroidManifest.xml 中为我在 Android 上添加此解决问题:
<application .... />
// add queries tag for mailto intent out side of application tag
<queries>
<intent>
<action android:name="android.intent.action.SENDTO" />
<data android:scheme="mailto" />
</intent>
</queries>
答案 1 :(得分:0)
我在iPhone上遇到了同样的问题,这是由于我没有设置默认的iOS默认邮件应用程序引起的。
答案 2 :(得分:0)
确保 Android Gradle 插件高于 4.1.0,您会在 android\build.gradle
文件中找到类似这样的内容
dependencies { classpath 'com.android.tools.build:gradle:4.1.1' "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'com.google.gms:google-services:4.3 .4' }
2。将它添加到您的 android/app/src/main/AndroidManifest.xml
文件中,紧跟在您添加 <uses-permission>
<queries> <intent> <action android:name="android.intent.action.SENDTO" /> <data android:scheme="mailto" /> </intent> </queries>
flutter clean
flutter pub get
或者您可以运行您的代码,它会在 Flutter 电子邮件发送程序包适合您之后为您执行此操作
这为我解决了问题