flutter web之WebSocketChannelException错误

编程入门 行业动态 更新时间:2024-10-24 01:48:33

flutter web之WebSocketChannelException<a href=https://www.elefans.com/category/jswz/34/1771449.html style=错误"/>

flutter web之WebSocketChannelException错误

flutter最近新功能增加挺多,试了FFI后,尝试下flutter web,但是执行flutter run -d chrome时却报如下错误:

~/w/f/flutter_web_demo ❯❯❯ flutter run -d chrome                                                                   ✘ 1
Launching lib/main.dart on Chrome in debug mode...
Building application for the web...    
⣻WebSocketChannelException: WebSocketChannelException: 
SocketException: 
Failed host lookup: 'localhost' (OS Error: nodename nor servname provided, or not known, errno = 8)⣻^C

报错报的莫名其妙。。。原来没发布时用webdev尝试flutter_web的工程也没有问题啊

网上搜了下,都是一些和我这个完全不搭的问题,只能自己尝试解决了。

仔细看了下报错信息:

Failed host lookup: 'localhost' (OS Error: nodename nor servname provided, or not known

localhost找不到,为什么呢?

忽然想到了今天安装了SwitchHosts!,然后修改了/etc/hosts。打开/etc/hosts看下内容,果然一篇空白,什么都没有。使用SwitchHosts!还原默认hosts文件,也就是增加如下内容到hosts:

127.0.0.1	localhost

重新运行flutter run -d chrome,运行成功,自动打开chrome,完美。

正常输出:

~/w/f/flutter_web_demo ❯❯❯ flutter run -d chrome                                                                              ✘ 130
Launching lib/main.dart on Chrome in debug mode...
Building application for the web...                                21.3s
Attempting to connect to browser instance..                         6.4s? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
Warning: Flutter's support for building web applications is highly experimental.
For more information see [.](.)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??  To hot restart (and rebuild state), press "R".
For a more detailed help message, press "h". To quit, press "q".
Debug service listening on ws://127.0.0.1:57994/Bt0EHzyriqw=

我原创发于:

更多推荐

flutter web之WebSocketChannelException错误

本文发布于:2024-03-09 14:25:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1725227.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   flutter   web   WebSocketChannelException

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!