更新Flutter到新版本3.22.0时,遇到警告:
“不推荐使用‘FlutterLoader.loadEntrypoint’。请改用‘FlutterLoader.load’。”
从“loadEntrypoint”更改为“load”后,我遇到了另一个问题:
“FlutterLoader.load 需要设置 _flutter.buildConfig”
在查看 flutter.js 时,我意识到“load”函数比“loadEntrypoint”有更多参数
请问有谁知道这个问题的解决办法吗,请提供建议。
我今天就遇到了这个问题,花了一些时间查看文档和发行说明,这就是我发现的: https://docs.flutter.dev/platform-integration/web/bootstrapping
他们改进了网络应用程序初始化:
index.html
,您的代码应如下所示: <body>
<script src="flutter_bootstrap.js" async></script>
</body>
<body>
<script>
window.addEventListener('load', function(ev) {
{{flutter_js}}
{{flutter_build_config}}
_flutter.loader.load({
serviceWorker: {
serviceWorkerVersion: {{flutter_service_worker_version}},
},
onEntrypointLoaded: function(engineInitializer) {
engineInitializer.initializeEngine().then(function(appRunner) {
if(document.getElementById('splash'))
document.getElementById('splash').remove();
appRunner.runApp();
});
}
});
});
</script>
<picture id="splash" >
<source srcset="splash/img/iso_gradient_vert-x3.png 1x" media="(prefers-color-scheme: light) or (prefers-color-scheme: no-preference)">
<source srcset="splash/img/iso_gradient_vert-x3.png 1x" media="(prefers-color-scheme: dark)">
<img class="center" src="splash/img/iso_gradient_vert-x3.png" width="500" height="500" alt="LOGO"/>
</picture>
</body>
希望有帮助!