Skip to content

Use flutterRoot instead of looking for the flutter package when reading the sdk path from .package_config.json #5728

Closed

Description

@incendial

Is your feature request related to a problem? Please describe.
Right now extractFlutterSdkPathFromPackagesFile tries to read the path to the "flutter" package and this works well for flutter projects, but does not work for pure dart projects.

Describe the solution you'd like
In ".package_config.json" there seem to be a field called "flutterRoot" which points to the sdk and is present regardless of the flutter package (and even created when running "dart pub get", though I have flutter installed on my device).

The URIs differ a bit, though:

  1. "rootUri": "file://.../Desktop/flutter/packages/flutter",
  2. "flutterRoot": "file://.../Desktop/flutter",

Maybe it's worth it to read the "flutterRoot" field instead?

Describe alternatives you've considered
_

Additional context
_

Activity

  1. added
    is enhancementAn enhancement or improvement that should be listed in release notes but is not a bug fix.
    on Sep 27, 2025
  2. DanTup commented on Sep 27, 2025

    @DanTup
    Member

    this works well for flutter projects, but does not work for pure dart projects.

    It's not clear to me why we would want to find the Flutter SDK from pure dart projects - are you having a problem that you think this would solve?

  3. added
    awaiting infoRequires more information from the customer to progress
    on Sep 27, 2025
  4. incendial commented on Sep 27, 2025

    @incendial
    Author

    For tools like asdf the location of the sdk is dynamic and after reading this comment #5377 (comment) I though that it can work for pure dart projects as well but now I'm not sure that you actually want to always find the flutter sdk here (and below)

    const flutterSdkPathFromCommand = config.getFlutterSdkCommand && await this.runCustomGetSDKCommand(config.getFlutterSdkCommand, "dart.getFlutterSdkCommand", !!config.workspaceGetFlutterSdkCommand);

    What I can tell is that you try to transform the path in extractFlutterSdkPathFromPackagesFile (remove unnecessary parts), but the flutterRoot already has the correct path. Why not to simplify it?

  5. incendial commented on Sep 27, 2025

    @incendial
    Author

    If you don't see that as an improvement for the sdk detection, feel free to close the issue

  6. DanTup commented on Sep 27, 2025

    @DanTup
    Member

    I'm not sure, I'd have to look up when it's populated to understand how it would change what we have today. I wanted to understand if there was a situation you had in mind where this would improve/change something (I wasn't sure if you'd hit a problem that you thought this would fix).

  7. DanTup commented on Oct 1, 2025

    @DanTup
    Member

    What I can tell is that you try to transform the path in extractFlutterSdkPathFromPackagesFile (remove unnecessary parts), but the flutterRoot already has the correct path. Why not to simplify it?

    I did some testing, and this field is populated for non-Flutter Dart packages if you use the Dart SDK from a Flutter SDK so we'd need to be careful not to use this as a signal that this project is Flutter (however the current call for this function already checks that). So maybe it's worth changing (to avoid some extra path manipulation) as long as we make that behaviour clear.

    For tools like asdf the location of the sdk is dynamic and after reading this comment #5377 (comment) I though that it can work for pure dart projects as well

    There is an equivalent dart.getDartSdkCommand setting for non-Flutter projects, but I don't know if it handles what you had in mind?

  8. removed
    awaiting infoRequires more information from the customer to progress
    on Oct 1, 2025
  9. added this to the v3.122.0 milestone on Oct 1, 2025
  10. incendial commented on Oct 1, 2025

    @incendial
    Author

    There is an equivalent dart.getDartSdkCommand setting for non-Flutter projects, but I don't know if it handles what you had in mind?

    That is not an equivalent in a sense that it requires manual setup.

    I personally don't use asdf, so again, feel free to close this if you don't see this as an improvement. IMO, finding the sdk automatically is always better than asking for a manual setup. That's why I opened this issue.

  11. DanTup commented on Oct 2, 2025

    @DanTup
    Member

    That is not an equivalent in a sense that it requires manual setup.

    I'm not sure I understand - the getFlutterSdkCommand version you linked also requires manual setup. They are two settings that allow us to call our to external tools to get the SDK paths, one for Dart, one for Flutter. If you use something like asdf you still need to configure it so we run the correct command.

    IMO, finding the sdk automatically is always better than asking for a manual setup.

    I absolutely agree with this (which is why we search many places for SDKs!), but I don't think switching from the flutter package path in package_config.json to flutterRoot will change any behaviour here, it will just simplify our path manipulation (avoiding us having to strip packages/flutter off the end to find the SDK root.

  12. modified the milestones: v3.122.0, v3.124.0 on Oct 29, 2025
  13. modified the milestones: v3.124.0, v3.126.0 on Nov 20, 2025
  14. modified the milestones: v3.126.0, v3.128.0 on Dec 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    is enhancementAn enhancement or improvement that should be listed in release notes but is not a bug fix.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions