如何在Visual Studio Code中为Flutter添加外部包?执行命令未生效
flutter packages get Not Working in VS Code Hey there! I’ve run into this exact issue before, so let’s walk through the most common fixes to get your english_words dependency loaded properly.
1. Double-Check Your pubspec.yaml Format
YAML is super picky about indentation and syntax—even a missing space can break things. Make sure your dependency entry is correctly formatted, with proper alignment under dependencies:
dependencies: flutter: sdk: flutter english_words: ^3.1.0 # Ensure this line uses 2 spaces (same indent as the "flutter" line above)
Also, verify there are no typos in the package name or version number (e.g., no extra characters like spaces after the version).
2. Run the Command Directly in the Terminal
Sometimes the VS Code command panel doesn’t show error messages that would clue you in to the problem. Open the VS Code terminal (press `Ctrl + `` to toggle it) and run:
flutter pub get
This is the updated version of flutter packages get (both work, but pub get is preferred now). Watch for any error output here—common issues include network timeouts, dependency conflicts, or missing SDK configurations.
3. Verify Your Flutter SDK Path in VS Code
If VS Code isn’t pointing to the correct Flutter SDK installation, it might fail to resolve dependencies. To check:
- Open VS Code settings (
Ctrl + ,) - Search for Flutter SDK Path
- Ensure the path matches where you installed Flutter on your machine (e.g.,
C:\flutteron Windows,~/flutteron macOS/Linux) - If you update the path, restart VS Code and try
flutter pub getagain.
4. Restart VS Code & Clear Flutter Cache
Editor glitches or cached data can sometimes block dependency resolution. Try these steps:
- Close VS Code completely, then reopen it
- In the terminal, run
flutter cleanto clear old build artifacts - Then run
flutter pub getagain
5. Check Network Connectivity
If you’re behind a firewall or in a region with restricted access to pub.dev, the package fetch might fail. You can try:
- Switching to a different network (like a mobile hotspot)
- Configuring a domestic pub mirror (if applicable) by setting these environment variables before running
pub get:# For macOS/Linux export PUB_HOSTED_URL=https://pub.flutter-io.cn export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn # For Windows (Command Prompt) set PUB_HOSTED_URL=https://pub.flutter-io.cn set FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
After setting these, run flutter pub get again.
If none of these work, share the error message you see in the terminal—specific errors will help narrow down the exact issue!
内容的提问来源于stack exchange,提问作者twiddly

