[英]Flutter run url from default browser using url_launcher
我正在使用url_launcher (6.1.5),我想在默认浏览器中打开 url,而不是在应用程序中打开 webView。
似乎最新版本不支持它,因为launch function 已被弃用,并且launchUrl不支持forceWebView=false
标志。
如何使用 url_launcher 在默认浏览器上运行url_launcher
?
您可以使用LaunchMode.externalApplication
参数。
await launchUrl(_url, mode: LaunchMode.externalApplication);
默认情况下, mode
值设置为LaunchMode.platformDefault
,在大多数情况下是inAppWebView
。
更改mode
解决了这个问题:
Future<void> openUrl(String url) async {
final _url = Uri.parse(url);
if (!await launchUrl(_url, mode: LaunchMode.externalApplication)) { // <--
throw Exception('Could not launch $_url');
}
}
LaunchMode
支持几种arguments:
enum LaunchMode {
/// Leaves the decision of how to launch the URL to the platform
/// implementation.
platformDefault,
/// Loads the URL in an in-app web view (e.g., Safari View Controller).
inAppWebView,
/// Passes the URL to the OS to be handled by another application.
externalApplication,
/// Passes the URL to the OS to be handled by another non-browser application.
externalNonBrowserApplication,
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.