← Back to Blog

Flutter pub get Proxy Errors: How to Configure pub.dev and Fix SocketException

Flutter pub get fails with an error when working through a proxy? We analyze the causes of SocketException, TimeoutException, and SSL errors, and provide a working configuration of environment variables for pub.dev.

📅November 24, 2026

If the command flutter pub get fails with a timeout error or SocketException when you are working through a corporate or personal proxy, the problem is almost always due to incorrect configuration of environment variables or blocking of pub.dev at the network level. In this article, we will analyze all common errors and provide working configurations for Windows, macOS, and Linux.

Why Flutter developers need a proxy for pub.dev

In practice, a proxy for working with Flutter and pub.dev is needed in several scenarios. The first is a corporate environment where all outgoing traffic must pass through a corporate proxy server due to security requirements. The second is regional restrictions: pub.dev and googleapis.com, from which dependencies are pulled, may not be directly accessible in some countries or may have an unstable connection, causing CI/CD builds to fail due to timeouts.

The third scenario is testing multi-regional Flutter applications, where it is necessary to check how the API client behaves with different geolocations, requiring the build to go through a proxy from a specific country. The fourth involves developers working in offices with strict traffic filtering (China, parts of corporate networks in the Middle East), where direct access to pub.dev is blocked at the DNS or firewall level, and the only working option is an external proxy server.

In all these cases, the Flutter SDK and pub (the Dart package manager) must be explicitly instructed through which server to fetch dependencies. Without this, the toolchain will attempt to resolve pub.dev directly and fail with network errors.

Common errors of flutter pub get through a proxy

Let's analyze five errors that are most commonly encountered when using pub through a proxy and explain their root causes.

1. SocketException: Connection timed out

Got socket error trying to find package meta_seo at https://pub.dev.
  SocketException: Connection timed out (OS Error:
  Connection timed out, errno = 110), address = pub.dev, port = 443

This error means that pub attempted to connect to pub.dev directly, ignoring the proxy. Most often, the reason is that the environment variables HTTP_PROXY / HTTPS_PROXY are not exported in the current terminal session or were set only for one shell process.

2. HandshakeException: Handshake error in client (OS Error: CERTIFICATE_VERIFY_FAILED)

This occurs when the corporate proxy replaces the SSL certificate (MITM proxy for traffic analysis), and the Dart VM does not trust the root certificate of the proxy server. It can be resolved by adding the certificate to the system's trusted root certificate store or through the environment variable SSL_CERT_FILE.

3. Could not resolve host: pub.dev

This is a DNS resolution error. It indicates that the proxy is configured only for HTTP(S) traffic of applications, but DNS queries are sent directly, bypassing the proxy, and the provider or firewall blocks DNS to pub.dev. The solution is to use a SOCKS5 proxy with remote DNS resolution or to add pub.dev to the hosts file with the IP of the proxy tunnel.

4. 407 Proxy Authentication Required

The proxy requires authentication with a username and password, but the URL of the proxy passed in the environment variable does not include the credentials or includes unescaped special characters (for example, "@" in the password breaks URL parsing).

5. pub get hangs indefinitely (freezes without error)

A common issue when using unstable free proxy lists is that the connection is established, but the proxy "drops" the packet in the middle of data transfer. This can be resolved by switching to a paid stable proxy pool with guaranteed uptime.

Setting up HTTP_PROXY and HTTPS_PROXY environment variables

The Dart SDK and, consequently, pub use the standard environment variables HTTP_PROXY and HTTPS_PROXY. It is important to set both, as pub.dev operates over HTTPS, while some dependencies (package archives) may sometimes be pulled over HTTP.

Linux and macOS (bash/zsh)

export HTTP_PROXY="http://login:password@proxy_host:port"
export HTTPS_PROXY="http://login:password@proxy_host:port"
export NO_PROXY="localhost,127.0.0.1"

flutter pub get

If the password contains special characters (for example, @, #, :), they need to be encoded using URL encoding: @ → %40.

Windows (PowerShell)

$env:HTTP_PROXY="http://login:password@proxy_host:port"
$env:HTTPS_PROXY="http://login:password@proxy_host:port"

flutter pub get

To keep the variables between terminal restarts, set them through system settings: Control Panel → System → Advanced system settings → Environment Variables, or with the command setx HTTP_PROXY "http://proxy_host:port".

Windows (cmd)

set HTTP_PROXY=http://login:password@proxy_host:port
set HTTPS_PROXY=http://login:password@proxy_host:port

flutter pub get

Important: Environment variables set through export or $env: only exist within the current terminal session. If you open a new IDE window (Android Studio, VS Code) without restarting, it may not pick up the proxy — restart the IDE completely after setting the variables.

Configuring pub.dev through .bashrc, .zshrc, and system variables

To avoid manually entering the proxy each time, add the export of the variables to your shell configuration file. For bash, this is ~/.bashrc, for zsh — ~/.zshrc:

echo 'export HTTP_PROXY="http://login:password@proxy_host:port"' >> ~/.zshrc
echo 'export HTTPS_PROXY="http://login:password@proxy_host:port"' >> ~/.zshrc
source ~/.zshrc

If you want the proxy to apply only to pub and not to the entire system (for example, you use curl and git with a different proxy), you can set the variable right before the command — it will only apply for that single call:

HTTP_PROXY="http://proxy_host:port" HTTPS_PROXY="http://proxy_host:port" flutter pub get

Dart also supports a separate VM flag for debugging network issues: running with --verbose with pub will show the exact URL being accessed and help determine whether pub is using the proxy at all:

flutter pub get -v

Proxy in CI/CD: GitHub Actions, GitLab CI, Codemagic

If the Flutter project build is taking place in a CI/CD environment located in a region with restricted access to pub.dev, or if you need to simulate a build from a specific country for testing a geo-dependent API, the environment variables are set through CI secrets.

GitHub Actions — add the variables in the job:

jobs:
  build:
    runs-on: ubuntu-latest
    env:
      HTTP_PROXY: ${{ secrets.PROXY_URL }}
      HTTPS_PROXY: ${{ secrets.PROXY_URL }}
    steps:
      - uses: actions/checkout@v4
      - uses: subosito/flutter-action@v2
      - run: flutter pub get
      - run: flutter build apk

GitLab CI — variables are set in the variables section:

variables:
  HTTP_PROXY: "http://proxy_host:port"
  HTTPS_PROXY: "http://proxy_host:port"

flutter_build:
  script:
    - flutter pub get
    - flutter build apk

For a stable CI/CD build, it is critically important to use a proxy with high uptime and without IP rotation in the middle of the build — otherwise, the TCP session may be interrupted in the middle of downloading a large package (for example, firebase_core or google_maps_flutter), and the build will fail with a partially downloaded cache in ~/.pub-cache.

Which type of proxy to choose for Flutter development

For working with pub.dev, anonymity is not as important as the stability of the connection and speed. Let's consider which type of proxy is suitable for different developer tasks.

Proxy Type When to use for Flutter Speed
Datacenter Proxies CI/CD builds, development without geo-IP binding requirements High
Residential Proxies Testing application API from a specific country, bypassing pub.dev blocks in traffic-filtered regions Medium
Mobile Proxies Testing a mobile Flutter application with a real mobile IP from the carrier Medium-low

For daily local development and regular calls to flutter pub get, a datacenter proxy is the optimal choice — it provides minimal latency and a stable connection without the risk of interruption in the middle of package loading. If the task is to check how your Flutter application interacts with an external REST API considering user geolocation (for example, regional prices or content), residential proxies with real IPs from the required country will be suitable.

Proxy troubleshooting checklist

Before writing to support or Stack Overflow, go through this list — in 90% of cases, the problem can be resolved with one of these steps.

  1. Check that the variables are set in the current terminal session: echo $HTTP_PROXY (Linux/macOS) or echo $env:HTTP_PROXY (PowerShell)
  2. Check the proxy directly through curl, bypassing Flutter: curl -x http://proxy_host:port https://pub.dev
  3. Ensure that the password in the proxy URL is URL-encoded if it contains special characters
  4. Clear the pub cache: flutter pub cache repair
  5. Restart the IDE completely if the environment variables were set after it was opened
  6. Check if the antivirus or corporate firewall is blocking the proxy port (usually 8080, 3128, or 1080 for SOCKS5)
  7. For SOCKS5, use the prefix socks5:// instead of http:// in the environment variable
  8. If the error is related to the SSL certificate, add the root certificate of the proxy to the system's trusted certificate store

Conclusion

Most errors of flutter pub get when working through a proxy boil down to three reasons: incorrectly set environment variables HTTP_PROXY/HTTPS_PROXY, untrusted SSL certificate of the corporate proxy, and instability of the proxy server itself, which drops the connection in the middle of package loading. Go through the checklist above, and in most cases, the problem will be resolved in 10-15 minutes.

If you are setting up a CI/CD build or testing a Flutter application considering user geolocation, the stability of the proxy is critical — a TCP session interruption in the middle of loading the google_maps_flutter or firebase_core package leads to a corrupted cache and repeated build failures. For stable development, datacenter proxies with low latency are more suitable, while for testing regional scenarios, residential proxies with real IPs from the required country will be appropriate.