升级后 Flutter 中的弃用警告

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

升级 Flutter 后,我遇到了以下两个与我的 index.html 文件相关的警告:

Warning: In index.html:37: Local variable for "serviceWorkerVersion" is deprecated. Use "{{flutter_service_worker_version}}" template token instead.
Warning: In index.html:46: "FlutterLoader.loadEntrypoint" is deprecated. Use "FlutterLoader.load" instead.

这些警告表明我的index.html 文件中的某些元素正在使用已弃用的方法。这是我当前的index.html 文件:

    <!DOCTYPE html>
    <html>
    <head>
      <!--
        If you are serving your web app in a path other than the root, change the
        href value below to reflect the base path you are serving from.
    
        The path provided below has to start and end with a slash "/" in order for
        it to work correctly.
    
        For more details:
        * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
    
        This is a placeholder for base href that will be replaced by the value of
        the `--base-href` argument provided to `flutter build`.
      -->
      <base href="$FLUTTER_BASE_HREF">
    
      <meta charset="UTF-8">
      <meta content="IE=Edge" http-equiv="X-UA-Compatible">
      <meta name="description" content="chapter 04">
    
      <!-- iOS meta tags & icons -->
      <meta name="apple-mobile-web-app-capable" content="yes">
      <meta name="apple-mobile-web-app-status-bar-style" content="black">
      <meta name="apple-mobile-web-app-title" content="flutter_layout">
      <link rel="apple-touch-icon" href="icons/Icon-192.png">
    
      <!-- Favicon -->
      <link rel="icon" type="image/png" href="favicon.png"/>
    
      <title>flutter_layout</title>
      <link rel="manifest" href="manifest.json">
    
      <script>
        // The value below is injected by flutter build, do not touch.
        const serviceWorkerVersion = null;
      </script>
      <!-- This script adds the flutter initialization JS code -->
      <script src="flutter.js" defer></script>
    </head>
    <body>
      <script>
        window.addEventListener('load', function(ev) {
          // Download main.dart.js
          _flutter.loader.loadEntrypoint({
            serviceWorker: {
              serviceWorkerVersion: serviceWorkerVersion,
            },
            onEntrypointLoaded: function(engineInitializer) {
              engineInitializer.initializeEngine().then(function(appRunner) {
                appRunner.runApp();
              });
            }
          });
        });
      </script>
    </body>
    </html>
  1. 如何使用
    serviceWorkerVersion
    模板标记正确替换
    {{flutter_service_worker_version}}
    变量?
  2. 如何更新
    FlutterLoader.loadEntrypoint
    方法以使用新的
    FlutterLoader.load
    方法?

我感谢有关如何解决这些弃用警告的任何指导或示例。谢谢!

flutter
1个回答
0
投票

web/index.html

1.替换serviceWorkerVersion

来自

const serviceWorkerVersion = null;

const serviceWorkerVersion = {{flutter_service_worker_version}};

2.要修复 FlutterLoader.loadEntrypoint 警告,请替换 body

来自

<body>
<script>
    window.addEventListener('load', function(ev) {
      // Download main.dart.js
      _flutter.loader.loadEntrypoint({
        serviceWorker: {
          serviceWorkerVersion: serviceWorkerVersion,
        },
        onEntrypointLoaded: function(engineInitializer) {
          engineInitializer.initializeEngine().then(function(appRunner) {
            appRunner.runApp();
          });
        }
      });
    });
</script>
</body>

<body>
<script src="flutter_bootstrap.js" async></script>
</body>
© www.soinside.com 2019 - 2024. All rights reserved.