Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

platformViewRegistry.registerViewFactory func is missing in import dart.ui #41563

Open
zengfr opened this issue Sep 29, 2019 · 58 comments
Open
Labels
a: build Building flutter applications with the tool a: error message Error messages from the Flutter framework customer: crowd Affects or could affect many people, though not necessarily a specific customer. found in release: 1.22 Found to occur in 1.22 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue is ready to work on. P5 Priority 5 issue (default for new feature requests; things we'd like to work on) platform-web Web applications specifically

Comments

@zengfr
Copy link

zengfr commented Sep 29, 2019

Upgrading-from-package:flutter_web-to-the-Flutter-SDK in flutter>=1.9
import 'package:flutter_web_ui/ui.dart' as ui change to import 'dart.ui '
ui.platformViewRegistry.registerViewFactory func is missing.

import 'package:flutter_web_ui/ui.dart' as ui;
 ui.platformViewRegistry.registerViewFactory(
        'maphtml',
            (int viewId) => IFrameElement()
          ..allowFullscreen=true
          ..height = '360'
          ..src = 'https://github.com/zengfr?'+_params
          ..style.border = 'none');

https://github.com/flutter/flutter/wiki/Upgrading-from-package:flutter_web-to-the-Flutter-SDK
Update the pubspec.yaml
Change:
dependencies:
flutter_web: any
flutter_web_ui: any
to:
dependencies:
flutter:
sdk: flutter

@GaspardMerten
Copy link

GaspardMerten commented Sep 29, 2019

The problem is just that the analyser version of Flutter does not yet support dart:ui or dart:js! So you should be able to build your app and it will work as expected because the version of Flutter that is used to build/run has dart:ui!

@escamoteur
Copy link
Contributor

escamoteur commented Sep 29, 2019

For Flutter Web I recommend to use the master channel.
Could you please add the output of flutter doctor - v here

@escamoteur escamoteur added a: build Building flutter applications with the tool a: error message Error messages from the Flutter framework platform-web Web applications specifically labels Sep 29, 2019
@zengfr
Copy link
Author

zengfr commented Sep 29, 2019

For Flutter Web I recommend to use the master channel.
Could you please add the output of flutter doctor - v here

E:\javaproject\flutterwebdemo\examples\myweb>flutter doctor - v
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel master, v1.10.7-pre.70, on Microsoft Windows [Version 10.0.10240], locale zh-CN)
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[√] Chrome - develop for the web
[√] Android Studio (version 3.5)
[√] IntelliJ IDEA Ultimate Edition (version 2019.1)
[√] Connected device (2 available)

• No issues found!

E:\javaproject\flutterwebdemo\examples\myweb>

@escamoteur
Copy link
Contributor

escamoteur commented Sep 29, 2019

Do you still have the problem?

@zengfr
Copy link
Author

zengfr commented Sep 29, 2019

is use D:\flutter>flutter upgrade Still have problems

error: The name 'platformViewRegistry' is being referenced through the prefix 'ui', but it isn't defined in any of the libraries imported using that prefix. (undefined_prefixed_name at [myweb] lib\agent\map.dart:12)

import 'dart:html';
import 'package:flutter/material.dart';
import 'dart:ui' as ui;

class MapPage extends StatefulWidget {
final String _params;

MapPage({String params}) : _params = params;

@OverRide
State createState() {
ui.platformViewRegistry.registerViewFactory(
'maphtml',
(int viewId) => IFrameElement()

Flutter 1.10.7-pre.73 • channel master • https://github.com/flutter/flutter.git
Framework • revision 67b5bdf (16 hours ago) • 2019-09-28 14:24:46 -0700
Engine • revision 5b952f2
Tools • Dart 2.6.0 (build 2.6.0-dev.3.0 6ff8d2199d)

Running flutter doctor...
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel master, v1.10.7-pre.73, on Microsoft Windows [Version 10.0.10240], locale zh-CN)
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[√] Chrome - develop for the web
[√] Android Studio (version 3.5)
[√] IntelliJ IDEA Ultimate Edition (version 2019.1)
[√] Connected device (2 available)

• No issues found!

D:\flutter>

@Abhilash-Chandran
Copy link

Abhilash-Chandran commented Sep 30, 2019

Same issue in my case.

[√] Flutter (Channel master, v1.10.7-pre.79, on Microsoft Windows [Version 10.0.17134.950], locale de-DE)
• Flutter version 1.10.7-pre.79 at C:\Abhilash\Installs\flutter
• Framework revision 7e73cd7 (77 minutes ago), 2019-09-30 14:45:30 +0100
• Engine revision 5b952f2
• Dart version 2.6.0 (build 2.6.0-dev.3.0 6ff8d2199d)

[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at C:\Users\xyz\AppData\Local\Android\sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.0.3
• Java binary at: C:\Users\xyz\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\191.5791312\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
• All Android licenses accepted.

[√] Chrome - develop for the web
• Chrome at C:\Users\xyz\AppData\Local\Google\Chrome\Application\chrome.exe

[√] Android Studio (version 3.4)
• Android Studio at C:\Users\xyz\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\183.5692245
• Flutter plugin version 38.2.1
• Dart plugin version 183.6270
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)

[√] Android Studio (version 3.5)
• Android Studio at C:\Users\xyz\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\191.5791312
• Flutter plugin version 39.0.3
• Dart plugin version 191.8423
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)

[√] VS Code (version 1.38.1)
• VS Code at C:\Users\xyz\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.4.1

[√] Connected device (2 available)
• Chrome • chrome • web-javascript • Google Chrome 77.0.3865.90
• Server • web • web-javascript • Flutter Tools

• No issues found!

@rostopira
Copy link
Contributor

rostopira commented Oct 4, 2019

Why can't we just add empty function with same declaration in ios/android engine to silence this warning? That shouldn't take a week to fix

@escamoteur
Copy link
Contributor

escamoteur commented Oct 4, 2019

@rostopira Flutter Web is still in preview. 5 days ago we got this reported. We currently over 5000 open issues so it depends on the priority an issue has how fast it is Fixed.
You can make a PR to speed up things

@jan-pavlovsky
Copy link

jan-pavlovsky commented Oct 30, 2019

Facing the same issue now and it is a real show-breaker unfortunately :/ Would be great if this could be fixed soooon... Thanks :)

@Fox32

This comment has been minimized.

@muhleder
Copy link

muhleder commented Oct 30, 2019

It compiles for web but fails on mobile. I'm using conditional imports as a workaround for that.

FakeUi.dart

// ignore: camel_case_types
class platformViewRegistry {
  static registerViewFactory(String viewId, dynamic cb) {}
}

RealUi.dart

import 'dart:ui' as ui;

// ignore: camel_case_types
class platformViewRegistry {
  static registerViewFactory(String viewId, dynamic cb) {
    // ignore:undefined_prefixed_name
    ui.platformViewRegistry.registerViewFactory(viewId, cb);
  }
}

and then to use in a widget

import 'FakeUi.dart' if (dart.library.html) 'RealUi.dart' as ui;

@venshine

This comment has been minimized.

@carman247
Copy link

carman247 commented Feb 19, 2020

The problem is just that the analyser version of Flutter does not yet support dart:ui or dart:js! So you should be able to build your app and it will work as expected because the version of Flutter that is used to build/run has dart:ui!

Thank you! This had me so confused

@yasinarik
Copy link

yasinarik commented May 11, 2020

    // ignore: undefined_prefixed_name
    ui.platformViewRegistry.registerViewFactory('drop_zone_div', (int viewId) {
      return innerDivElement;
    });

Today I have upgraded from 1.15.3 dev channel ---> to 1.19.0-1.0.pre.27 master channel and the above code works no more. It doesn't ignore and shows it as an error always.

@muhleder
Copy link

muhleder commented May 11, 2020

@yasinarik In your analysis_options.yaml you can add a global

analyzer:
  errors:
    undefined_prefixed_name: ignore

Not sure if that can be restricted to just the one file.

@sabowsla
Copy link

sabowsla commented Feb 21, 2021

@migalv correct, the analyzer is not tolerating this anymore. The current solution involves creating a stub, or maybe using the plugin created by @flutterlabz here.

this worked for me, the plugin created by @flutterlabz

@dvaldivia
Copy link

dvaldivia commented Mar 7, 2021

it'd be nice if the solution by @flutterlabz is posted to github so we can move it to null safety, this missing ui is preventing upgrades to null safety

@ditman
Copy link
Member

ditman commented Mar 8, 2021

@dvaldivia
Copy link

dvaldivia commented Mar 8, 2021

@ditman thanks! it's not on pub.dev so I totally missed it

@ditman
Copy link
Member

ditman commented Mar 8, 2021

it's not on pub.dev so I totally missed it

@dvaldivia That's also a good contribution for the pubspec.yaml of the package, add a repository entry haha :P

@creativecreatorormaybenot
Copy link
Contributor

creativecreatorormaybenot commented Mar 9, 2021

@ditman https://github.com/flutterlabz/universal_ui/pull/1 :P

@ditman
Copy link
Member

ditman commented Mar 9, 2021

I've migrated the shim (well, our own copy) to null-safety here, in case anybody needs help with the migration :) https://github.com/flutter/packages/tree/master/packages/pointer_interceptor/lib/src/shim

@singerdmx
Copy link

singerdmx commented Mar 26, 2021

Is this fixed? Our pub https://pub.dev/packages/flutter_quill/score is missing 30 points because of this
What are we supposed to do about this?

@ditman
Copy link
Member

ditman commented Mar 30, 2021

@singerdmx it seems you rolled your own fix for this.

@singerdmx
Copy link

singerdmx commented Mar 30, 2021

I remove the code
It is not fix

@LautaroLobo12
Copy link

LautaroLobo12 commented Apr 9, 2021

I'm facing this issue too. Using Dart SDK 2.12.2 and Flutter 2.0.3.

@jeremiahlukus
Copy link

jeremiahlukus commented Apr 13, 2021

same issue..

± |master ✓| → flutter --version
Flutter 2.1.0-12.2.pre • channel beta • git@github.com:flutter/flutter.git
Framework • revision 5bedb7b1d5 (4 weeks ago) • 2021-03-17 17:06:30 -0700
Engine • revision 711ab3fda0
Tools • Dart 2.13.0 (build 2.13.0-116.0.dev)


± |master U:1 ✗| → dart --version
Dart SDK version: 2.12.2 (stable) (Wed Mar 17 10:30:20 2021 +0100) on "macos_x64"

@LautaroLobo12
Copy link

LautaroLobo12 commented Apr 15, 2021

I solved it by reading the docs, lol

For android, You must have to update minSdkVersion to 21 (or higher).

From the Take a picture using the camera tutorial.

@AdeAnima
Copy link

AdeAnima commented Apr 21, 2021

Same issue here.

I solved it by reading the docs, lol

For android, You must have to update minSdkVersion to 21 (or higher).

From the Take a picture using the camera tutorial.

Honestly no idea, how this should solve this problem ^^

@AdeAnima
Copy link

AdeAnima commented May 23, 2021

Honestly emberassing that this is still open after 2 years

@creativecreatorormaybenot
Copy link
Contributor

creativecreatorormaybenot commented May 23, 2021

What are you saying @AdeAnima?

This is only a minor inconvenience.
You can simply use the shim (example here) and you are good to go! So this is not an actual problem.

@lirantzairi
Copy link

lirantzairi commented Oct 13, 2021

In both iOS and Android, the PlatformViewFactory is a class that has a create(...) method which can take a dynamic args parameter. This way the view can be created with arguments (there are many use cases for this). However, in dart web it seems (correct me if I'm wrong) that the PlatformViewFactory is a dypedef for a function that only gets the view ID and returns an html element.
Allowing to pass arguments is very important. Can you please support this?

Thanks.

@ditman
Copy link
Member

ditman commented Oct 14, 2021

Allowing to pass arguments is very important. Can you please support this?

@lirantzairi What's a good use case for arguments in web platform views? They're "almost" supported in web (missing a connection between the HtmlElementView widget and the engine), but in my experience I haven't been blocked by not having creation parameters so far?

@lirantzairi
Copy link

lirantzairi commented Oct 14, 2021

@ditman One use case I've stumbled upon is when integrating Mapbox (see https://docs.mapbox.com/mapbox-gl-js/guides/install/#quickstart). When creating the view, I need to set some parameters like the map url, camera position, etc.
The same requirement exists for iOS and Android but there it's not a problem because you can pass parameters to the creation of the view.

@ditman
Copy link
Member

ditman commented Oct 14, 2021

@lirantzairi I see, in that case you could use the HtmlElementView to render:

<div id='map' style='width: 400px; height: 300px;'></div>

And deal with the initialization script (from Dart) once that's rendered; we do something similar in Google Maps:

  • Register the "_div" here.
  • Call the initialization code on the "div" here

(We also have one-factory-per-map-Id too)

Another question @lirantzairi: does it work for you with only a single map, and injecting both the

and the <script> tag in the HtmlElementView?

@RafiqCR7
Copy link

RafiqCR7 commented Jun 29, 2022

What are you saying @AdeAnima?

This is only a minor inconvenience. You can simply use the shim (example here) and you are good to go! So this is not an actual problem.

How can you make use of the shim?

@ditman
Copy link
Member

ditman commented Jun 29, 2022

How can you make use of the shim?

@RafiqCR7 you import ui from the shim, instead of directly. See this:

https://github.com/flutter/plugins/blob/670ade44963f9ba307a258331419dc42ff5ca91f/packages/video_player/video_player_web/lib/video_player_web.dart#L12-L15

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: build Building flutter applications with the tool a: error message Error messages from the Flutter framework customer: crowd Affects or could affect many people, though not necessarily a specific customer. found in release: 1.22 Found to occur in 1.22 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue is ready to work on. P5 Priority 5 issue (default for new feature requests; things we'd like to work on) platform-web Web applications specifically
Projects
None yet