Skip to content

Using multiple "flutter apps" inside a page using Element Embedding #121374

@eduardo-pellenz

Description

@eduardo-pellenz

Use case

I'm currently writing a chart library for the company that I work for. After some research, we didn't find a good package that have the features that we want. So our decision was to write our own.

We have both an web app and app (React and Flutter). And with the Element Embedding feature we want to reuse this package for both platforms.

After some tests using the master branch, there was two things that I found that would be really cool to add/improve (don't actually know if it's on your roadmap already)

Proposal / Questions

I wasn't able to create two instances of the app. Is there or will be a way to create multiple instances of the app in a page? This is the code that I have used.

const initChart = (targetSelector) => {
  let target = document.querySelector(targetSelector);
  _flutter.loader.loadEntrypoint({
    onEntrypointLoaded: async function (engineInitializer) {
      let appRunner = await engineInitializer.initializeEngine({
        hostElement: target,
      });
      await appRunner.runApp();
    },
  });
}

window.addEventListener("load", function (ev) {
  initChart('#flutter_target');
  initChart('#flutter_target_2');
});

With this code, the first app is stopped and the second one works.

Will be there a way to export single widgets instead of having to export the whole app?

Using the current way, it's possible to achieve what I want using a wrapper around the _flutter.loader.loadEntrypoint and calling the state methods to update the state. But will be there a better way to do that?

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Fluttercustomer: googleVarious Google teamsengineflutter/engine related. See also e: labels.frameworkflutter/packages/flutter repository. See also f: labels.platform-webWeb applications specificallyteam-webOwned by Web platform teamtriaged-webTriaged by Web platform team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions