Flutter Webview不适用于Flutter Web
我正在尝试通过URL在webview
中显示一个网页.
我已经尝试过flutter_webview_plugin
插件,但是当我在浏览器中运行该项目时,该插件无法正常工作.
I am trying to show a webpage in webview
via URL.
I have tried flutter_webview_plugin
plugin but it was not working when I run the project on the browser.
还有其他方法可以在颤动的Web应用程序中显示网页吗?
Is there any another way to show the webpage in the flutter web application?
flutter_webview_plugin将网页嵌入到应用程序中.在Flutter网站中,您应该使用HtmlElementView
小部件.
那里的大多数演示都使用IFrameElement
嵌入网页.您可以检查此 easy_web_view 软件包,以自动处理移动平台和Web平台.
根据部署情况,它会在内部自动使用HTMLElementView
和WebView
.
flutter_webview_plugin is to embed web pages inside an app. In flutter web you should use HtmlElementView
widget.
Most demos out there use IFrameElement
to embed a webpage. You can check this easy_web_view package for handling both mobile and web platform automatically.
It internally uses HTMLElementView
and WebView
automatically depending on the case of the deployment.
在此处
更新以添加onLoad侦听器
IFrameElement iframeElement = IFrameElement()
..src = 'url'
..style.border = 'none'
..onLoad.listen((event) {
// perform you logic here.
});
ui.platformViewRegistry.registerViewFactory(
'webpage',
(int viewId) => iframeElement,
);
return Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: SizedBox(
width: double.infinity,
height: double.infinity,
child: HtmlElementView(viewType: 'webpage'),
),
),
);