Flutter HTML内容的颤振URL启动器不工作
我正在开发一个应用程序使用颤振。现在,我需要在包含锚链接的应用程序中呈现HTML内容。但是HTML内容中的链接有一个问题,它在单击时没有在浏览器中打开链接 这是我的密码Flutter HTML内容的颤振URL启动器不工作,flutter,Flutter,我正在开发一个应用程序使用颤振。现在,我需要在包含锚链接的应用程序中呈现HTML内容。但是HTML内容中的链接有一个问题,它在单击时没有在浏览器中打开链接 这是我的密码 Container( color: Colors.white, padding: EdgeInsets.only(top: 10, right: 10, bottom: 10, left: 10),
Container(
color: Colors.white,
padding: EdgeInsets.only(top: 10, right: 10, bottom: 10, left: 10),
child: Html(
data: htmlContent,
onLinkTap: (link) {
launch(link);
},
))
当我点击它时,它不工作
我在顶部导入了这个库
import 'package:url_launcher/url_launcher.dart';
我的代码有什么问题,如何修复?在HTML中打开链接对我来说是这样的:
Html(
data: 'This is some <a href="https://pub.dev/packages/url_launcher">link</a>',
onLinkTap: (url) async {
if (await canLaunch(url)) {
await launch(
url,
);
} else {
throw 'Could not launch $url';
}
},
)
Html(
数据:'这是一些',
onLinkTap:(url)异步{
如果(等待canLaunch(url)){
等待发射(
网址,
);
}否则{
抛出“无法启动$url”;
}
},
)
请注意,在使用launch
打开链接之前,我首先等待canLaunch
方法
你的链接是什么?你能给我们举个例子吗?谢谢
onLinkTap: (url) async {
if (await canLaunch(url)) {
await launch(
url,
);
} else {
throw 'Could not launch $url';
}
},
另外,不要忘了将其添加到清单文件中
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="https" />
</intent>
<intent>
<action android:name="android.intent.action.DIAL" />
<data android:scheme="tel" />
</intent>
<intent>
<action android:name="android.intent.action.SEND" />
<data android:mimeType="*/*" />
</intent>
</queries>
如果您提供一个工作示例或更多信息(什么是htmContent
的内容?引发的异常是什么?我假设您也使用flatter\u html
包),那么就更容易了。假设您有一个MissingPluginException:关闭应用程序并执行flatter run
(在cli中)应该可以工作。