# Pub get 失败（服务器不可用）-- 由于套接字异常无法解析包：OS 错误：连接被拒绝

- **ID:** `flutter/install-error-pub-get-failed-socket`
- **领域:** flutter
- **类别:** install_error
- **验证级别:** ai_generated
- **修复率:** 82%

## 根因

由于网络问题、防火墙阻止或 DNS 解析失败，pub.dev 服务器或自定义包仓库无法访问。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| flutter 3.10 | active | — | — |
| flutter 3.22 | active | — | — |
| dart 3.0 | active | — | — |
| dart 3.5 | active | — | — |

## 解决方案

1. ```
   检查网络连接并确保 pub.dev 可访问。临时禁用 VPN 或防火墙，然后运行 'flutter pub get --offline'（如果依赖已缓存），或使用镜像，设置 PUB_HOSTED_URL 为镜像地址。
   ```
2. ```
   使用不同的 DNS 服务器（例如 Google DNS 8.8.8.8）或在防火墙/代理设置中添加 pub.dev 的例外。
   ```

## 无效尝试

- **Repeatedly running 'flutter pub get' without any network changes** — The underlying network issue persists; retrying does not resolve connectivity problems. (95% 失败率)
- **Deleting the pubspec.lock file and running pub get again** — The lock file is not the cause; the error is network-related, so deletion has no effect. (85% 失败率)
