FlutterLoader 没有为 web 定义

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

我有问题
我不知道为什么,但我的网络应用程序构建正确,但是当我在网络上使用 chrome 时,我有白页,并且在控制台中出现错误:FlutterLoader 未定义

我的index.html页面如下所示:

<!DOCTYPE html>
<html>
<head>
  <base href="$FLUTTER_BASE_HREF">

  <meta charset="UTF-8">
  <meta content="IE=Edge" http-equiv="X-UA-Compatible">
  <meta name="description" content="A new Flutter project.">

  <!-- 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="architect_schwarz_admin">
  <link rel="apple-touch-icon" href="icons/Icon-192.png">

  <!-- Favicon -->
  <link rel="icon" type="image/png" href="favicon.png"/>

  <title>web admin</title>
  <link rel="manifest" href="manifest.json">

  <script>
    // The value below is injected by flutter build, do not touch.
    const serviceWorkerVersion = '{{flutter_service_worker_version}}';
  </script>
  <!-- This script adds the flutter initialization JS code -->
  <script src="flutter.js" defer></script>
</head>
<body>
  <script>
    window.addEventListener('load', function(ev) {
      if (typeof FlutterLoader !== 'undefined') {
        // Download main.dart.js
        FlutterLoader.load({
          serviceWorker: {
            serviceWorkerVersion: serviceWorkerVersion,
          },
          onEntrypointLoaded: function(engineInitializer) {
            engineInitializer.initializeEngine().then(function(appRunner) {
              appRunner.runApp();
            });
          }
        });
      } else {
        console.error('FlutterLoader is not defined.');
      }
    });
  </script>
</body>
</html>

来自控制台谷歌浏览器的图像
enter image description here

你知道问题出在哪里吗?

flutter flutter-dependencies
1个回答
0
投票

查看官方文档

这不是

FlutterLoader
,而是:


_flutter.loader.loadEntrypoint({
          serviceWorker: {

我想您使用的是已弃用的版本。

您的整个 index.html 应如下所示:

<!DOCTYPE html>
<html>
<head>
  <base href="$FLUTTER_BASE_HREF">

  <meta charset="UTF-8">
  <meta content="IE=Edge" http-equiv="X-UA-Compatible">
  <meta name="description" content="A new Flutter project.">

  <!-- 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="architect_schwarz_admin">
  <link rel="apple-touch-icon" href="icons/Icon-192.png">

  <!-- Favicon -->
  <link rel="icon" type="image/png" href="favicon.png"/>

  <title>web admin</title>
  <link rel="manifest" href="manifest.json">

  <script>
    // The value below is injected by flutter build, do not touch.
    const serviceWorkerVersion = '{{flutter_service_worker_version}}';
  </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: async function(engineInitializer) {
        // Initialize the Flutter engine
        let appRunner = await engineInitializer.initializeEngine();
        // Run the app
        await appRunner.runApp();
      }
    });
  });
</script>
</body>
</html>

如您所见,控制台中没有错误:

enter image description here

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