我正在尝试通过 URL 在 webview
中显示网页。
我试过 flutter_webview_plugin
插件,但是当我在浏览器上运行项目时它不起作用。
在 flutter web application 中有没有其他方法可以显示网页?
最佳答案
flutter_webview_plugin 是将网页嵌入到应用程序中。在 flutter web 中,你应该使用 HtmlElementView
小部件。
大多数演示都使用 IFrameElement
来嵌入网页。你可以查看这个easy_web_view用于自动处理移动和网络平台的软件包。
它在内部根据部署情况自动使用 HTMLElementView
和 WebView
。
一些例子可用here
添加 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'),
),
),
);
关于flutter-web - Flutter Webview 不适用于 Flutter web,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61499763/