Skip to content

[flutter_tools] pubspec.yaml environment.flutter constraint not respected by pub get #95472

Description

@neiljaywarner

steps to reproduce

  1. use current stable version flutter 2.8.1
  2. in pubspec.yaml use flutter: ">=2.8.0 <2.8.1" or "2.8.0"

Expected behaviour - flutter pub get error

The current Flutter SDK version is 2.8.1.

Because app_name requires Flutter SDK version <2.8.1, version solving failed.

Actual behaviour: pub get succeeds; vesrion constraint fails, overzealous dev or build server just ugpraded to a newer version of flutter without discussion or any testing at all or possibly even an easy OOTB way to see what version was built with

Activity

  1. darshankawar commented on Dec 20, 2021

    @darshankawar
    Member

    @neiljaywarner
    Is there any reason why you need to change it to >=2.8.0 <2.8.1" or "2.8.0" ?
    On latest stable 2.8.1, the dart version supported is 2.15.1 (from flutter doctor) .

  2. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Dec 20, 2021
  3. github-actions commented on Jan 10, 2022

    @github-actions

    Without additional information, we are unfortunately not sure how to resolve this issue. We are therefore reluctantly going to close this bug for now.
    If you find this problem please file a new issue with the same description, what happens, logs and the output of 'flutter doctor -v'. All system setups can be slightly different so it's always better to open new issues and reference the related ones.
    Thanks for your contribution.

  4. neiljaywarner commented on Jan 10, 2022

    @neiljaywarner
    Author

    @darshankawar sorry I didn't see your question.
    I want to pin it so if I go away for 6 to 18 months and come back I know what flutter version this project expects and will compile on.
    Yes I know updating is important but so is keeping everyone on a project on the same tested version

  5. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jan 10, 2022
  6. neiljaywarner commented on Jan 10, 2022

    @neiljaywarner
    Author
  7. darshankawar commented on Jan 11, 2022

    @darshankawar
    Member

    The current version with upper constraint I have is sdk: ">=2.8.1 <3.0.0" which works well, indicating the min lower and max upper version constraint, so I am not entirely sure what your request here is.

  8. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jan 11, 2022
  9. neiljaywarner commented on Jan 11, 2022

    @neiljaywarner
    Author
  10. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jan 11, 2022
  11. darshankawar commented on Jan 12, 2022

    @darshankawar
    Member

    Keeping it open and labeling for further input.

  12. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    on Jan 12, 2022
  13. 41 remaining items

  14. dsyrstad commented on May 14, 2025

    @dsyrstad

    It is true that Flutter does not use semantic versioning for breaking releases. But presumably we could still support upper bounds on environment.flutter. :)

    ...Or perhaps a flag in pubspec.yaml saying you want to enforce strict version checking for the flutter sdk. This would be backwards compatible with existing pubspecs. Along the lines of:

    environment:
      sdk: '>=3.5.0 <4.0.0'
      flutter: 3.29.2
      strict_flutter_version_checking: true
  15. eseidel commented on May 14, 2025

    @eseidel
    Contributor

    It looks like this behavior was originally added in dart-lang/pub@d74520a Which appears to have been a request from Tim Sneath. 🤣 #68143

  16. eseidel commented on May 14, 2025

    @eseidel
    Contributor

    My guess is what's happening here is the divergence of desires between packages and applications. I expect that Tim's original request was so that not every flutter-using package in the Dart ecosystem would need an update just because Flutter announced Flutter 2, since by default ^1.0.0 will disallow usage of the package with Flutter 2 and thus the day that Flutter 2 was announced, you couldn't use it because all of your packages (which probably would work fine) suddenly would refuse to work with your version of Flutter because it was now not aligned with the ^1.0.0 constraint.

    However this also meant that then Apps were no longer able to restrict the version of Flutter used, because (at least the way it was implemented) apps no longer had a way to specify they wanted exactly 1.0.0.

    This is in part due to how Flutter uses (abuses?) semver, by having X.Y.Z and Z is incremented on each hotfix. Y is incremented every month (e.g. beta release) and X was intentionally controlled by product management and arbitrarily incremented every time we wanted to make a splash about flutter haven't changed enough that we should have an event, etc.

  17. eseidel commented on May 14, 2025

    @eseidel
    Contributor

    Anyway, I think I'm stuck at this point. I can't get a working test environment for pub locally (7 tests fail for me) and I have other demands on my time. So I may look at this again (or someone else should feel free to attempt to 1. get pub tests working locally and 2. finish the posted patch). My guess is that the proper solution here is going to be to one of:

    • splitting behavior of "apps" vs. "packages" (not sure how that would work?)
    • adding a new key to pubspec.yaml to be a real flutter constraint
    • adding some new key to opt in to this behavior
    • give up on this behavior and just make it so that when Flutter 4 is announced, all pub packages depending on flutter won't work with Flutter 4, because their constraints will be >=3 <4 🤷

    If anyone would like to pick up where I left off dart-lang/pub#4578 has a PR (including a text file containing the 7 failures I'm seeing locally with a clean Dart 3.7.3 sdk archive for Arm64 mac from https://dart.dev/get-dart/archive

  18. eseidel commented on May 16, 2025

    @eseidel
    Contributor

    To restate (for clarity) the problem that I understand this bug to be about.

    There is no official way to record "this app should be built with version x.y.z of Flutter".

    As currently implemented, if one use the environment.flutter constraint, one would, at minimum, need to look at the pubspec.yaml rather than pubspec.lock because the spec might say 1.2.3 but the lock will say >=1.2.3.

    This arrises because of the workaround added in dart-lang/pub@d74520a. That workaround was targeted a libraries to avoid a library which was OK with Fluter 1.x suddenly needing to re-publish when Flutter 2.x was released, even though 2.x had no breaking changes for that library. When the flutter/dart ecosystem was smaller, that was a very bad thing for Flutter 2 release day. :)

    There are lots of 3p attempts at adding ways to express "this app should be built with flutter x.y.z". fvm, puro, etc. have per-package "lock" files for a flutter version. There is just no "flutter official" place to put this information.

    How we (shorebird) got involved here was simply that we were attempting to teach shorebird to determine the version of Flutter to use for building a project (as part of fixing shorebirdtech/shorebird#2529). When we realized the environment.flutter method was unreliable, we had 3 options: we (shorebird) make yet another way, fix this one, or bless one of these 3p ways as being the "standard".

    It's not a huge blocker for us. Just attempting to re-summarize this long issue and explain why my attention got drawn to this (briefly) this week.

  19. neiljaywarner commented on May 16, 2025

    @neiljaywarner
    Author

    Oh two other quick comments

    1. I'm working with a very large Enterprise right now and concerns about upgrading flutter have come up
    2. It's a really big problem in my opinion that since you can't pin the flutter version if you set aside something and come back to at 6 or 12 months later, you don't even know what flutter version it was built with
  20. AlexV525 commented on May 16, 2025

    @AlexV525
    Member

    Some unthoughtful idea: How about introducing "!x.y.z" for specific version constraint pin?

  21. sigurdm commented on Jun 3, 2025

    @sigurdm
    Contributor

    After discussing this offline we ended up agreeing that we will change pub to respect the upper bound flutter constraint for any root pubspec (that is, the pubspecs of the workspace).

    That is a breaking change, but most likely not very disruptive, as usually you can change the pubspecs of the workspace, while it is harder to.

  22. eseidel commented on Jun 4, 2025

    @eseidel
    Contributor

    Sounds good. I think the only time it will be "disruptive" is when Google launches Flutter 4.0 and it takes months for ones favorite packages to work with 4.0. (As I recall that was the original motivation for this current behavior was launching Flutter 2.0.)

  23. mit-mit commented on Jun 4, 2025

    @mit-mit
    Member

    Right, but that is a lot less disruptive for a root pubspec (for those the developer likely owns the source code and can quickly update it), than it is for the many packages that are listed as dependencies in that root pubspec. These packages often come from pub, and would need a coordinated effort across the ecosystem to get the contraints updated.

  24. sigurdm commented on Jun 16, 2025

    @sigurdm
    Contributor
  25. added
    r: fixedIssue is closed as already fixed in a newer version
    on Jun 17, 2025
  26. github-actions commented on Jul 1, 2025

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  27. locked as resolved and limited conversation to collaborators on Jul 1, 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

    P2Important issues not at the top of the work listc: regressionIt was better in the past than it is nowr: fixedIssue is closed as already fixed in a newer versionteam-toolOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-toolTriaged by Flutter Tool team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions