gpt4 book ai didi

flutter - 在URL中使用URL启动器发送电子邮件时出现问题

转载 作者:行者123 更新时间:2023-12-03 13:28:34 31 4
gpt4 key购买 nike

您好,我尝试启动带配方的电子邮件页面。我尝试了 flutter 的电子邮件发件人,我可以在Android上使用它,但不能在ios上使用。因此,我尝试使用url启动器执行相同的操作,但不能与iOS一起使用。我使用iOS模拟器,可能是这个问题吗?

我使用这个网址启动器示例

mailto:xxxxx@xxxxx.com?subject=News&body=New%20plugin

我有这个错误
[VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: Could not launch mailto:xxxx@xxxx.com?subject=News&body=New%20plugin
#0 _menuscreenState._launchURL (package:xxxx/bottom.dart:8285:7)
<asynchronous suspension>
#1 _menuscreenState.build.<anonymous closure>.<anonymous closure> (package:xxxx/bottom.dart:8705:13)

这是url启动器的完整示例
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {


String email="contact@ouiquit.com";
_launchEmail() async {
if (await canLaunch("mailto:$email")) {
await launch("mailto:$email");
} else {
throw 'Could not launch';
}
}

@override
Widget build(BuildContext context) {


return MaterialApp(
theme: ThemeData(primaryColor: Colors.red),
home: Scaffold(
appBar: AppBar(
title: Text('test mail'),
actions: <Widget>[
IconButton(
onPressed: _launchEmail,
icon: Icon(Icons.send),
)
],
),


),
);
}


}

这是错误
[VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: MissingPluginException(No implementation found for method canLaunch on channel plugins.flutter.io/url_launcher)
#0 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:314:7)
<asynchronous suspension>
#1 canLaunch (package:url_launcher/url_launcher.dart:112:25)
<asynchronous suspension>
#2 _MyAppState._launchEmail (package:testmail/main.dart:20:15)
<asynchronous suspension>
#3 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:654:14)
#4 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:729:32)
#5 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
#6 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:365:11)
#7 TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:275:7)
#8 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/<…>

最佳答案

这对我在Android和iOS设备上均有效:

如果您也有querysubject,请添加body参数。

final Uri params = Uri(
scheme: 'mailto',
path: 'email@example.com',
query: 'subject=App Feedback&body=App Version 3.23', //add subject and body here
);

var url = params.toString();
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}

关于flutter - 在URL中使用URL启动器发送电子邮件时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57989859/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com