Flutter 项目运行在chorme 时提示:Failed to establish connection with the application instance in Chrome.

自己学习flutter项目开发APP时,想运行到chrome上看一下效果,运行时提示:

Launching lib/main.dart on Chrome in debug mode...
SocketException: Failed host lookup: 'localhost' (OS Error: nodename nor servname provided, or not known, errno = 8)
#0      _NativeSocket.lookup.<anonymous closure> (dart:io-patch/socket_patch.dart:520:9)
#1      _rootRunUnary (dart:async/zone.dart:1407:47)
#2      _CustomZone.runUnary (dart:async/zone.dart:1308:19)
<asynchronous suspension>
#3      WebAssetServer.start (package:flutter_tools/src/isolated/devfs_web.dart:200:18)
<asynchronous suspension>
#4      WebDevFS.create (package:flutter_tools/src/isolated/devfs_web.dart:762:22)
<asynchronous suspension>
#5      ResidentWebRunner.run.<anonymous closure> (package:flutter_tools/src/isolated/resident_web_runner.dart:305:25)
<asynchronous suspension>
#6      asyncGuard.<anonymous closure> (package:flutter_tools/src/base/async_guard.dart:111:24)
<asynchronous suspension>

Failed to establish connection with the application instance in Chrome.
This can happen if the websocket connection used by the web tooling is unable to correctly establish a connection, for example due to a firewall.

然后通过终端检查本地hosts文件里是否有127.0.0.1的配置,发现没有


 

sudo vi /etc/hosts

然后插入:

127.0.0.1       localhost

 保存后,在项目里运行到chrome就可以了

  • 10
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值