Skip to content

[web] HtmlElementView has no onPlatformViewCreated #56181

Closed
@deakjahn

Description

@deakjahn

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.

Activity

added
a: platform-viewsEmbedding Android/iOS views in Flutter apps
frameworkflutter/packages/flutter repository. See also f: labels.
platform-webWeb applications specifically
c: new featureNothing broken; request for a new capability
on May 4, 2020
deakjahn

deakjahn commented on May 6, 2020

@deakjahn
Author

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

deakjahn commented on May 7, 2020

@deakjahn
Author

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 commented on May 7, 2020

@yjbanov
Contributor

@hterkelsen can you please triage this?

deakjahn

deakjahn commented on Jul 13, 2020

@deakjahn
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. :-)

added
P3Issues that are less important to the Flutter project
and removed
assigned for triageissue is assigned to a domain expert for further triage
on Aug 13, 2020
RaghuMudem

RaghuMudem commented on Feb 19, 2021

@RaghuMudem

Any solution for this, onPlatformViewCreated for HtmlElementView ?

18 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projecta: platform-viewsEmbedding Android/iOS views in Flutter appsc: new featureNothing broken; request for a new capabilityframeworkflutter/packages/flutter repository. See also f: labels.platform-webWeb applications specificallyr: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @yjbanov@harryterkelsen@deakjahn@LichKing-2234@RaghuMudem

        Issue actions

          [web] HtmlElementView has no onPlatformViewCreated · Issue #56181 · flutter/flutter