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
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:
flutter --version
flutter upgrade flutter --version
environment:
sdk: ">=3.5.4 <4.0.0"
flutter channel stable
flutter upgrade
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:
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.