[英]Flutter run url from default browser using url_launcher
I'm using url_launcher (6.1.5) and I want open the urls in default browser instead of in-app webView.我正在使用url_launcher (6.1.5),我想在默认浏览器中打开 url,而不是在应用程序中打开 webView。
It seems that the latest version does not support it, since launch function is deprecated, and launchUrl does not support the forceWebView=false
flag.似乎最新版本不支持它,因为launch function 已被弃用,并且launchUrl不支持
forceWebView=false
标志。
How do I run my url on default browser using url_launcher
?如何使用 url_launcher 在默认浏览器上运行
url_launcher
?
You can use the LaunchMode.externalApplication
parameter.您可以使用
LaunchMode.externalApplication
参数。
await launchUrl(_url, mode: LaunchMode.externalApplication);
By default the mode
value is set to LaunchMode.platformDefault
, which in most cases is an inAppWebView
.默认情况下,
mode
值设置为LaunchMode.platformDefault
,在大多数情况下是inAppWebView
。
Changing the mode
solved this issue:更改
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
support several arguments: 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.