繁体   English   中英

Flutter 使用 url_launcher 从默认浏览器运行 url

[英]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

TL;博士

您可以使用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM