openHttpUrl function
打开 http(s) URL:支持端内 WebView 的平台优先半屏;否则 url_launcher 外开。
Implementation
Future<bool> openHttpUrl(
String url, {
BuildContext? context,
bool preferInAppWebView = true,
}) async {
final uri = normalizeHttpUri(url);
if (uri == null) return false;
final canInApp = preferInAppWebView &&
PlatformCapabilities.supportsInAppWebView &&
context != null &&
context.mounted;
if (canInApp) {
try {
await showInAppBrowser(context, uri.toString());
return true;
} catch (_) {
// 回落外开
}
}
try {
return await launchUrl(uri, mode: LaunchMode.externalApplication);
} catch (_) {
return false;
}
}