Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter - dart.ui no method 'platformViewRegistry'

Im working on Flutter web and I want to render an html code. Since flutter_webview_plugin doesnt support flutter web yet Im using IFrameElement and HtmlElementView. But I have this problem when using dart.ui, platformViewRegistry method isn't defined.

Error message:

The name 'platformViewRegistry' is being referenced through the prefix 'ui', but it isn't defined in any of the libraries imported using that prefix.

import 'dart:ui' as ui;
......
 ui.platformViewRegistry.registerViewFactory(
        createdViewId,
            (int viewId) => html.IFrameElement()
          ..width = MediaQuery.of(context).size.width.toString() //'800'
          ..height = MediaQuery.of(context).size.height.toString() //'400'
          ..srcdoc = """<!DOCTYPE html><html>
          <head><title>Page Title</title></head><body><h1>This is a Heading</h1><p>This is a paragraph.</p></body></html>"""            
          ..style.border = 'none');

Example Code From: https://stackoverflow.com/a/60089273/12789200

I read some solution to solve this problem. But I don't want to downgrade my flutter version. Since in the past month Flutter has a lot of changes

Flutter Doctor

[√] Flutter (Channel beta, 1.22.1, on Microsoft Windows [Version 10.0.19041.508], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[√] Chrome - develop for the web
[√] Android Studio (version 4.0)
[√] VS Code (version 1.49.3)
[√] Connected device (3 available)

Is there any other solution for this problem? Or another example I can used for WebView on Flutter Web.

like image 705
Raine Dale Holgado Avatar asked Sep 16 '25 15:09

Raine Dale Holgado


1 Answers

There is now a new API that solves the error:

import 'dart:ui_web' as ui_web; // New import for all web-only stuff...

...

ui_web.platformViewRegistry.registerViewFactory(...);

Ref: https://github.com/flutter/engine/pull/41877

like image 129
David Miguel Avatar answered Sep 19 '25 07:09

David Miguel