According to Flutter's Embedding a Flutter App you can utilize some JS to bootstrap the flutter app. This works great if your Flutter Web app is already hosted elsewhere.
Embedding a Flutter app into an HTML Page with Javascript
<html>
<head>
<!-- ... -->
<script src="flutter.js" defer></script>
</head>
<body>
<!-- Ensure your flutter target is present on the page... -->
<div id="flutter_host">Loading...</div>
<script>
window.addEventListener("load", function (ev) {
_flutter.loader.loadEntrypoint({
onEntrypointLoaded: async function(engineInitializer) {
let appRunner = await engineInitializer.initializeEngine({
// Pass a reference to "div#flutter_host" into the Flutter engine.
hostElement: document.querySelector("#flutter_host")
});
await appRunner.runApp();
}
});
});
</script>
</body>
</html>
Iframe Embed
Unfortunately for us we need a specific web route loaded for Flutter Web which this does not seem to handle. So we went with the other option they mention which is to utilize an iframe
element. This allowed us to point to a specific Flutter Web route and load up the associated Flutter web page.
There must be a way to specify a route with the JS bootstrapping, but I couldn't find anything explicit on their documentation. Hopefully they handle this in the future.
<iframe src="https://flutterWeb.url/some/path"></iframe>