flutterdartvisual-studio-codeasdf-vm

Version solving failed with running Dart commands using asdf in VSCode


I am needing to have multiple versions of Flutter installed so I switched from a regular installation of Flutter/Dart to having two versions of each with asdf. I am able to run Flutter commands without a problem, but attempting to run dart commands is not working and I am having to run them using Flutter (which is deprecated).

I am trying to use my globally installed version of Flutter (latest).

I am attempting this on a MacOS with Sonoma 14.5 and an Apple M1 Pro chip

I ran the command dart run build_runner build --delete-conflicting-outputs which gave me the following result:

Resolving dependencies in `[path/to/repo]`... 
Because [repo-name] depends on flutter_test from sdk which doesn't exist (the Flutter SDK is not available), version solving failed.

Flutter users should use `flutter pub` instead of `dart pub`.

So I attempted to run the command flutter pub run build_runner build --delete-conflicting-outputs, and this worked! However I am getting the following warning:

Deprecated. Use `dart run` instead.

This is after I added the following to my paths file:

/Users/myusername/.asdf/installs/flutter/3.22.2-stable/bin
/Users/myusername/.asdf/installs/flutter/3.27.1-stable/bin

as well as the following to my .zshrc file:

export PATH="$PATH":"/Users/myusername/.asdf/installs/flutter/3.22.2-stable/bin"
export PATH="$PATH":"/Users/myusername/.asdf/installs/flutter/3.27.1-stable/bin"

I have all of those paths listed as well in my VSCode settings, under the settings Dart: Sdk Paths and Dart: Flutter Sdk Paths and at the bottom status bar I have ensured that I have the right Flutter/Dart SDKs selected (Currently showing 3.27.1 - Flutter SDK and 3.6.0 (Flutter)Dart SDK)

flutter doctor results:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.27.1, on macOS 14.5 23F79 darwin-arm64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 16.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.2)
[✓] IntelliJ IDEA Ultimate Edition (version 2022.3.3)
[✓] VS Code (version 1.96.2)
[✓] VS Code (version 1.70.2)
[✓] Connected device (3 available)
[✓] Network resources

• No issues found!

Running flutter --version gives me the following:

Flutter 3.27.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 17025dd882 (2 weeks ago) • 2024-12-17 03:23:09 +0900
Engine • revision cb4b5fff73
Tools • Dart 3.6.0 • DevTools 2.40.2

Running dart --version gives me the following:

Dart SDK version: 3.6.0 (stable) (Thu Dec 5 07:46:24 2024 -0800) on "macos_arm64"

Solution

  • I have figured out what was wrong:

    Since I am using asdf, I have removed the following lines from my .zshrc file:

    export PATH="$PATH":"/Users/myusername/.asdf/installs/flutter/3.22.2-stable/bin"
    export PATH="$PATH":"/Users/myusername/.asdf/installs/flutter/3.27.1-stable/bin"
    

    I have uninstalled every version of Dart from asdf.
    In my workspace settings I have removed the dart.sdkPath setting entirely.

    The problem was that the stand-alone Dart SDK does not include Flutter, where the Flutter SDK does include the Dart SDK, therefore if using Flutter then the Dart SDK should not be referenced or even installed separately.