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

[web] HtmlElementView has no onPlatformViewCreated #56181

Closed
deakjahn opened this issue May 2, 2020 · 14 comments
Closed

[web] HtmlElementView has no onPlatformViewCreated #56181

deakjahn opened this issue May 2, 2020 · 14 comments
Labels
a: platform-views Embedding Android/iOS views in Flutter apps c: new feature Nothing broken; request for a new capability framework flutter/packages/flutter repository. See also f: labels. P3 Issues that are less important to the Flutter project platform-web Web applications specifically r: fixed Issue is closed as already fixed in a newer version

Comments

@deakjahn
Copy link

deakjahn commented May 2, 2020

HtmlElementView has no onPlatformViewCreated callback. This callback is primarily important to learn the viewId of the created view, for instance, to open the platform channel. The underlying code has its own callback in place but the call doesn't get propagated to the upper level.

@TahaTesser TahaTesser added a: platform-views Embedding Android/iOS views in Flutter apps framework flutter/packages/flutter repository. See also f: labels. platform-web Web applications specifically c: new feature Nothing broken; request for a new capability labels May 4, 2020
@deakjahn
Copy link
Author

deakjahn commented May 6, 2020

I went on with my code and realized that the problem is deeper than just asking for a new feature. The fact that there is no callback on creation means that there is no place to call any initialization from. When I create a new HtmlElementView, it's still premature to call any initialization because the actual PlatformViewLink isn't created yet, it will only come alive later in the build(), thus I can't find it in the DOM yet at that moment.

@deakjahn
Copy link
Author

deakjahn commented May 7, 2020

The optimal solution would be as simple as:

class HtmlElementView extends StatelessWidget {
  final String viewType;
  final PlatformViewCreatedCallback onPlatformViewCreated;
  final dynamic creationParams;

  const HtmlElementView({Key key, @required this.viewType, this.onPlatformViewCreated, this.creationParams})
      : assert(viewType != null),
        assert(kIsWeb, 'HtmlElementView is only available on Flutter Web.'),
        super(key: key);

  @override
  Widget build(BuildContext context) => PlatformViewLink(
        viewType: viewType,
        onCreatePlatformView: _createHtmlElementView,
        surfaceFactory: (BuildContext context, PlatformViewController controller) => PlatformViewSurface(
          controller: controller,
          gestureRecognizers: const <Factory<OneSequenceGestureRecognizer>>{},
          hitTestBehavior: PlatformViewHitTestBehavior.opaque,
        ),
      );

  _HtmlElementViewController _createHtmlElementView(PlatformViewCreationParams params) {
    final _HtmlElementViewController controller = _HtmlElementViewController(params.id, viewType);
    controller._initialize().then((_) {
      params.onPlatformViewCreated(params.id);
      onPlatformViewCreated(params.id); //!!!
    });
    return controller;
  }
}

In addition to the extra fields that make it on par with AndroidView and UIKitView, this actually means a single line added, marked with //!!!. It also makes way to provide the creation parameters that would be very comfortable, just like with the other platform counterparts. I don't really understand why you left that out in the first place, you had to work around this omission in your own plugins like video_player. :-)

@yjbanov yjbanov added the assigned for triage issue is assigned to a domain expert for further triage label May 7, 2020
@yjbanov
Copy link
Contributor

yjbanov commented May 7, 2020

@hterkelsen can you please triage this?

@deakjahn
Copy link
Author

@hterkelsen It seems that something is worked on with this control (eg. PlatformViewController.clearFocus() changed to async). Couldn't this be possibly a time to check this out? It's just a simple callback providing feature parity with other platforms, nothing dangerous. :-)

@yjbanov yjbanov added P3 Issues that are less important to the Flutter project and removed assigned for triage issue is assigned to a domain expert for further triage labels Aug 13, 2020
@RaghuMudem
Copy link

Any solution for this, onPlatformViewCreated for HtmlElementView ?

@deakjahn
Copy link
Author

deakjahn commented Feb 19, 2021

I use a custom type extended from the original one but it would be nice to see it implemented finally.

@LichKing-2234
Copy link
Contributor

My PR has been merged #84095. Now HtmlElementView support onPlatformViewCreated callback.

@MrBirb
Copy link
Contributor

MrBirb commented Jul 29, 2021

@TahaTesser Looks like this can be closed?

@deakjahn
Copy link
Author

@LichKing-2234 Is there any way to learn when it actually lands? Or do we need to check every time we upgrade Flutter?

@TahaTesser
Copy link
Member

Hi everyone
Closing as thehttps://github.com//pull/84095 is landed

@TahaTesser TahaTesser added the r: fixed Issue is closed as already fixed in a newer version label Jul 29, 2021
@LichKing-2234
Copy link
Contributor

@deakjahn you should run flutter channel master before it is stable.

@deakjahn
Copy link
Author

I certainly won't do that. I have plugins that rely on a workaround and I don't want to touch that before it goes into stable. I don't want to force my plugin users to unstable channels.

I guess it's trying it from time to time then...

@LichKing-2234
Copy link
Contributor

@deakjahn Sure, you can use it after it is stable.

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 16, 2021
deakjahn added a commit to deakjahn/flutter_dropzone that referenced this issue Sep 14, 2021
deakjahn added a commit to deakjahn/flutter_dropzone that referenced this issue Sep 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a: platform-views Embedding Android/iOS views in Flutter apps c: new feature Nothing broken; request for a new capability framework flutter/packages/flutter repository. See also f: labels. P3 Issues that are less important to the Flutter project platform-web Web applications specifically r: fixed Issue is closed as already fixed in a newer version
Projects
None yet
Development

No branches or pull requests

8 participants