Got socket error trying to find package flutter_lints at https://pub.dev Flutter pub.dev錯誤的解決方案

商君治国安邦之张莽發表於2024-04-17

最近想繼續玩下Flutter,發現pub.dev居然被封鎖了,試了下網上的方案,都不可行,嘗試組合了一下,用下面的方案解決了。

第一步:

找到這個檔案

D:\flutter\packages\flutter_tools\lib\src\http_host_validator.dart

把下面的地址修改為:

const String kPubDev = 'https://pub-web.flutter-io.cn/';
第二步:
設定系統變數

name: PUB_HOSTED_URL;
value: https://pub-web.flutter-io.cn

name: FLUTTER_STORAGE_BASE_URL;
value: https://storage.flutter-io.cn

執行flutter pub get 結果:

(base) PS D:\Project\Flutter\globaluniversity> flutter pub get
Resolving dependencies...
js 0.6.7 (0.7.1 available)
leak_tracker 10.0.0 (10.0.5 available)
leak_tracker_flutter_testing 2.0.1 (3.0.5 available)
leak_tracker_testing 2.0.1 (3.0.1 available)
material_color_utilities 0.8.0 (0.11.1 available)
meta 1.11.0 (1.14.0 available)
test_api 0.6.1 (0.7.1 available)
vm_service 13.0.0 (14.2.1 available)
Got dependencies!
8 packages have newer versions incompatible with dependency constraints.
Try `flutter pub outdated` for more information.

相關文章