创建Flutter Web的构建版本显示一个空白页面。

huangapple go评论66阅读模式
英文:

Creating a build version for flutter web shows an empty page

问题

以下是已翻译的内容:

我有一个基本的Flutter网站,当我运行flutter run -d chrome时,它在本地主机上运行正常,但当我准备发布它时,使用命令flutter build web,它显示一个空白页面并在控制台上抛出一些通用错误。

开发者选项中的控制台错误

检查其他答案,例如更改index.html页面上的href并没有起作用。
运行flutter doctor -v显示以下错误,我找不到有关此错误的有用信息,但引用的cocoapods网站不可用。

[!] HTTP主机可用性 X HTTP主机"https://cocoapods.org/"无法访问。原因:连接主机失败,超时时间为10秒

英文:

I have a basic flutter website that works fine in localhost when doing flutter run -d chrome, but when I was ready to publish it, with the command flutter build web, it shows a blank page and throw some generic errors by console.

Console errors on developer options

Checking other answers such as change the href on the index.html page aren't working.
Running flutter doctor -v is showing this error, which I can't find anything useful about, but the website cocoapods that is referencing is not available

[!] HTTP Host Availability
X HTTP host "https://cocoapods.org/" is not reachable. Reason: Failed to connect to host in 10 seconds

答案1

得分: 0

这涉及到CORS错误。解决这个问题的一种方法是使用HTML渲染器。

flutter build web --web-renderer html

或尝试这里的解决方案。链接

英文:

This has to deal with CORS error. one way of fixing this by using the HTML renderer.

flutter build web --web-renderer html

or try the solutions here. Link

答案2

得分: 0

谢谢您的回答 Adedokun,

所以,结果是我还在学习,而且根据这里的文档,index.html页面永远不会单独工作,您需要转到文件夹根目录并通过控制台启动服务器,在这种情况下,我使用 python -m http.server 8000 进行了操作,并在浏览器中导航到 localhost:8000,然后转到 build,然后 web。
另外,在 /build/web index.html 中,需要将 href="/" 更改为 href="./" 才能最终正常工作,似乎 href="" 也可以正常工作。
希望这对其他人也有帮助。

关于可用性,这只是暂时的,今天早上,flutter doctor 没有显示任何错误 创建Flutter Web的构建版本显示一个空白页面。

英文:

Thank you for your answer Adedokun,

So, turns out I'm still learning, and the index.html page is never going to work alone, according to the documentation here, you need to go to the folder root and launch a server by console, in this case I did with python -m http.server 8000, and navigated in a browser to localhost:8000, then go to build, then web.
Also, in the /build/web index.html, needed to change the href="/" to href="./" so it could work finally, it appears that href="" works too.
I hope this helps someone too.

and about the Availability, it was just temporal, this morning the flutter doctor didn't show any error 创建Flutter Web的构建版本显示一个空白页面。

huangapple
  • 本文由 发表于 2023年2月27日 11:56:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/75576661.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定