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)
Is there a way to display a WebView in Flutter Web ?
With the WebView Flutter plugin you can add a WebView widget to your Android or iOS Flutter app. On iOS the WebView widget is backed by a WKWebView, while on Android the WebView widget is backed by a WebView. The plugin can render Flutter widgets over the web view.
EDIT: Here is a runnable example as of May 16, 2021:
import 'dart:html';
import 'package:flutter/material.dart';
import 'dart:ui' as ui;
void main() {
// ignore: undefined_prefixed_name
ui.platformViewRegistry.registerViewFactory(
'hello-world-html',
(int viewId) => IFrameElement()
..width = '640'
..height = '360'
..src = 'https://www.youtube.com/embed/IyFZznAk69U'
..style.border = 'none');
runApp(Directionality(
textDirection: TextDirection.ltr,
child: SizedBox(
width: 640,
height: 360,
child: HtmlElementView(viewType: 'hello-world-html'),
),
));
}
The remainder of this post just replicates what's above, and is the original post by the original author
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');
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.
Also, you can use not only 'IFrameElement', it can be regular html:
ui.platformViewRegistry.registerViewFactory("simple_div", (int viewId) {
DivElement element = DivElement();
...
return element;
You can try using the easy_web_view plugin.
For iOS and Android, it uses the native webview_flutter plugin and for the Web, it does similar things from the @alex89607 answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With