Skip to content

Commit

Permalink
Revert "Revert "Use flutter.js bootstrapping (#2792)" (#2959)"
Browse files Browse the repository at this point in the history
This reverts commit 9183b0b.
  • Loading branch information
johnpryan committed May 9, 2024
1 parent 9183b0b commit 12d4f27
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ build/
# Or the files created by dart2js.
*.dart.js
*.js.deps
*.js.map

# Python generated files
*.pyc
Expand Down
7 changes: 5 additions & 2 deletions pkgs/dart_services/lib/src/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ import 'main.dart' as entrypoint;
Future<void> main() async {
registerPlugins(webPluginRegistrar);
await ui_web.bootstrapEngine();
entrypoint.main();
await ui_web.bootstrapEngine(
runApp: () {
return entrypoint.main();
},
);
}
''';

Expand Down
4 changes: 2 additions & 2 deletions pkgs/dartpad_ui/web/frame.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
margin-top: 0;
}
</style>
<script src="frame.js"></script>
<script src="require.js"></script>
<script id="compiled-script"></script>
<script src="flutter.js"></script>
<script src="frame.js"></script>
</head>

<body>
Expand Down
20 changes: 13 additions & 7 deletions pkgs/dartpad_ui/web/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,22 @@ function messageHandler(e) {
var obj = e.data;

if (obj.command === 'execute') {
// TODO: Switch to using engineInitializer.initializeEngine(config). See
// https://docs.flutter.dev/development/platform-integration/web/initialization.
window.flutterConfiguration = {
canvasKitBaseUrl: obj.canvasKitBaseUrl
};

replaceJavaScript(obj.js);
runFlutterApp(obj.js);
}
};

function runFlutterApp(compiledScript) {
var blob = new Blob([compiledScript], {type: 'text/javascript'});
var url = URL.createObjectURL(blob);
_flutter.loader.loadEntrypoint({
entrypointUrl: url,
onEntrypointLoaded: async function(engineInitializer) {
let appRunner = await engineInitializer.initializeEngine();
appRunner.runApp();
}
});
}

window.addEventListener('load', function () {
window.addEventListener('message', messageHandler, false);
parent.postMessage({ 'sender': 'frame', 'type': 'ready' }, '*');
Expand Down

0 comments on commit 12d4f27

Please sign in to comment.