skip to Main Content

When I try to run my flutter code in VS code it gives following error:
The current Dart SDK version is 3.1.0.

Because learning requires SDK version ^3.5.4, version solving failed.

You can try the following suggestion to make the pubspec resolve:

  • Try using the Flutter SDK version: 3.24.4.
    but in command prompt of my windows it works fine.

I was trying to run a flutter app in my physical device. I expected the app to be installed and run on my mobile to be tested but VS code throws the error(worked in cmd)

2

Answers


  1. The error you’re encountering happens because the Dart SDK version in your VS Code environment does not meet the required version for your project. The error message indicates that the project requires Dart SDK version ^3.5.4, while your VS Code setup is currently using version 3.1.0.

    Since you mentioned that the code runs fine when you use the command prompt, it seems that the Flutter environment in your command prompt is correctly configured (with the required SDK version), but VS Code might be using a different or outdated SDK version.

    Here’s how you can troubleshoot and fix this issue:

    1. Check Flutter SDK Version in VS Code.
      flutter --version
    2. Update the Flutter SDK in VS Code. flutter upgrade flutter --version
    3. Select the Correct Flutter SDK in VS Code.
    4. Check for pubspec.yaml Compatibility
      environment: sdk: ">=3.5.4 <4.0.0"
    5. Use the Correct Flutter Channel.
      flutter channel stable
      flutter upgrade
    6. Restart VS Code.
    7. Re-run the Flutter Project.
    8. Check for any Flutter DevTools or Extensions Updates.
    Login or Signup to reply.
  2. This issue typically happens if VS Code and Command Prompt are pointing to different Flutter SDK paths.

    Check and Verify Flutter SDK in VS Code:

    In VS Code, open the Command Palette (View > Command Palette), type "Flutter: Change SDK", and choose the correct Flutter path to match the version in CMD.

    Update Environment Variables:

    Ensure only the correct Flutter SDK path is in your system’s PATH. Remove if any duplicate or outdated paths found:

    • Go to > Windows: Go to System Properties > Environment Variables and adjust the PATH.
    • Restart VS Code and CMD to apply changes.

    Confirm Flutter sdk Version:

    Run flutter –version in both CMD and the VS Code terminal to verify they’re using the same SDK at both.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search