1

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.

Raine Dale Holgado
  • 2,932
  • 2
  • 17
  • 32

1 Answers1

2

Up to my knowledge I have tried several solutions and apparently there is a problem in the 'dart:ui' package . The solutions I've tried are:

  1. Tried using a WebView widget //Failed No web support yet
  2. Tried rendering on HTML instead of CanvasKit //UI will look rubbish
  3. Tried editing on the **analysis_options.yaml**
  4. Tried adding a comment above the code that said //ignore: undefined_prefixed_name

All these solutions referred to other errors, the solution was to use a package called: universal_ui from the https://pub.dev/packages/universal_ui , which is apparently the same as 'dart:ui' package, but with all methods included. Hope this works for you !

  • 2
    universal_ui isn't null safe, wondering what you're using if you're now null safe in your project. – jbryanh Jan 06 '22 at 17:42