FlutterLoader.loadEntrypoint”已弃用。请改用“FlutterLoader.load”

问题描述 投票:0回答:1

更新Flutter到新版本3.22.0时,遇到警告:

“不推荐使用‘FlutterLoader.loadEntrypoint’。请改用‘FlutterLoader.load’。”

从“loadEntrypoint”更改为“load”后,我遇到了另一个问题:

“FlutterLoader.load 需要设置 _flutter.buildConfig”

在查看 flutter.js 时,我意识到“load”函数比“loadEntrypoint”有更多参数

请问有谁知道这个问题的解决办法吗,请提供建议。

flutter
1个回答
0
投票

我今天就遇到了这个问题,花了一些时间查看文档和发行说明,这就是我发现的: https://docs.flutter.dev/platform-integration/web/bootstrapping

他们改进了网络应用程序初始化:

  1. 他们对 3.22.0 及更高版本创建的项目进行了更简单的回调。只需替换您的内容
    index.html
    ,您的代码应如下所示:
    <body>
      <script src="flutter_bootstrap.js" async></script>
    </body>
  1. 对于更复杂的情况,您仍然可以使用旧语法,但需要执行几个额外的步骤。例如,我在这里设置一个启动徽标图像,该图像在加载颤振时会被删除:
<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>

希望有帮助!

© www.soinside.com 2019 - 2024. All rights reserved.