自己学习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就可以了