gpt4 book ai didi

flutter - 如何阻止flutter web在每次构建时覆盖我的index.html?

转载 作者:行者123 更新时间:2023-12-03 04:14:29 31 4
gpt4 key购买 nike

所以我正在使用flutter web + cloud firestore

要让云 Firestore 正常工作,我必须修改我的 index.html。问题是每次我运行

flutter build web

它覆盖了我的 index.html,我必须手动重新添加所有必要的代码片段才能让它再次工作。

是一种我可以在不覆盖 index.html 的情况下运行 flutter build web 的方法吗?

另一个相关问题是,当我将站点部署到 firebase 时,它​​工作正常,但是当我在本地运行此站点以使用
flutter run -d chrome

当它在 chrome 上运行时,该站点再次使用全新的 index.html 没有必要的代码,因此它不起作用。我没有机会编辑 index.html 来应用必要的代码,因为它会立即构建和运行。

有解决办法吗?

最佳答案

你应该修改index.html <project>/web 中的文件文件夹,但不在 <project>/build/web 中文件夹。该文件将被复制到 <project>/build/web构建过程中的文件夹。

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>Flutter web</title>
<link href="https://fonts.googleapis.com/css?family=Raleway&display=swap" rel="stylesheet">
<script defer src="main.dart.js" type="application/javascript"></script>
<script src="https://www.gstatic.com/firebasejs/6.6.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/6.6.0/firebase-auth.js"></script>
</head>

<body>
<h1>This text will be copied to the target HTML, but covered by flutter web app</h1>
</body>

</html>

关于flutter - 如何阻止flutter web在每次构建时覆盖我的index.html?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61039702/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com