我有一个企业 Flutter 应用程序,主要是为 Android 和 iOS 开发的。我们添加了对 Windows 的支持。目前,该应用程序使用 webview 进行身份验证。以下是当前代码。
openBrowserOverlay(String url) {
if(Platform.isWindows) {
launchUrl(Uri.parse(url), mode: LaunchMode.inAppWebView);
} else {
FlutterWebBrowser.openWebPage(
url: url,
customTabsOptions: CustomTabsOptions(
instantAppsEnabled: true,
showTitle: true,
urlBarHidingEnabled: true,
),
safariVCOptions: SafariViewControllerOptions(
barCollapsingEnabled: true,
entersReaderIfAvailable: true,
modalPresentationCapturesStatusBarAppearance: true,
dismissButtonStyle: SafariViewControllerDismissButtonStyle.done,
),
);
}
}
flutter_inappwebview
软件包目前支持 Android 和 iOS。对于 Windows,我们使用 url_launcher
包,但它会在新窗口中打开网页。
怎么可以:
理想情况下,跨平台工作的包是最好的,但如果不可能,很乐意进行条件平台特定编码。
谢谢!
使用这个 Flutter 插件:
以及以下代码:
import 'package:webview_flutter/webview_flutter.dart';
return Scaffold(
appBar: AppBar(
title: const Text('WebView example'),
),
body: const WebView(
initialUrl: 'SOME URL',
javascriptMode: JavascriptMode.unrestricted,
),
);