【问题标题】:Flutter web, How to close or dismiss indext.html after loading the appFlutter web,加载应用程序后如何关闭或关闭 index.html
【发布时间】:2020-08-26 05:28:44
【问题描述】:

我自定义了indext.html 文件,并在其中添加了加载和图像,加载应用程序后,我的MaterialApp 出现并覆盖了indext.html 文件(看起来不错),但如果我使用我的页面的透明小部件,我可以在我的材料应用程序下方的indext.html 上看到加载和图像! 由于它们正在消耗资源,我如何在加载应用程序时停止 indext.html 上的加载状态?

【问题讨论】:

  • 在 index.html 中放一个 js 脚本,它会卸载所有不需要的元素
  • @Yadu,我不是 web 开发者,你能提供一个代码 sn-p 吗?

标签: flutter flutter-web


【解决方案1】:

感谢@Yadu,我已经实现了解决方案: 首先将 id 设置为 divs 将要隐藏(删除):

<div id="div1">
  ...
</div>

然后在index.html文件底部,修改flutter提供的script如下:

<script>
      if ("serviceWorker" in navigator) {
        window.addEventListener("load", function () {
          navigator.serviceWorker.register("flutter_service_worker.js");
          var div1 = document.getElementById("div1");

          setTimeout(function() { 
            div1.remove(); 
          }, 7000); // remove div by delay to make sure flutter module is completely loaded
        });
      }
    </script>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 2016-10-02
    • 1970-01-01
    相关资源
    最近更新 更多