Flutter Web中的WebView [英] WebView in Flutter Web

查看:60
本文介绍了Flutter Web中的WebView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Flutter for Web中显示Web视图,但出现以下错误:

I am trying to display a web view in Flutter for Web but I got the following error :

PlatformException(Unregistered factory, No factory registered for viewtype 'plugins.flutter.io/webview', null)

有没有办法在Flutter Web中显示WebView?

Is there a way to display a WebView in Flutter Web ?

推荐答案

您首先需要执行platformViewRegistry:

You need at first perform platformViewRegistry:

  ui.platformViewRegistry.registerViewFactory(
  'hello-world-html',
  (int viewId) => IFrameElement()
    ..width = '640'
    ..height = '360'
    ..src = 'https://www.youtube.com/embed/IyFZznAk69U'
    ..style.border = 'none');

查看该示例.在该示例中,导入了旧库(于19.09.19),但是如果您在"flutter"上更改"flutter_web",则该库必须正常工作.

Look at that example. In that example old library was imported (on 29.09.19), but if you change 'flutter_web' on 'flutter' it have to work.

此外,您不仅可以使用"IFrameElement",还可以使用常规的html:

Also, you can use not only 'IFrameElement', it can be regular html:

    ui.platformViewRegistry.registerViewFactory("simple_div", (int viewId) {
  DivElement element = DivElement();
  ...
  return element;

这篇关于Flutter Web中的WebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆