Search code examples
flutterdartyamlsemantic-versioning

why pubspec environment / sdk / uses " '>=2.7.0 <3.0.0' " instead of " ^2.7.0 "


to my, admittedly very limited, understanding of semver

this

environment:
  sdk: ^2.7.0

is equivalent to this

environment:
  sdk: '>=2.7.0 <3.0.0'

this format is strictly enforced for package publishing

Package validation found the following error:
* ^ version constraints aren't allowed for SDK constraints since older versions of pub don't support them.
  Expand it manually instead:
  
  environment:
    sdk: ">=2.7.0 <3.0.0"
Sorry, your package is missing a requirement and can't be published yet.

is there any reason why flutter uses the latter in place of the former approach,

which is arguably more familiar and consistent ?


Solution

  • Some definitions :

    • ^2.7.0 is Caret syntax
    • >=2.7.0 <3.0.0 is Traditional syntax

    And based on the documentation:

    Because caret syntax was introduced in Dart 1.8.3, it requires an SDK constraint (using traditional syntax) to ensure that older versions of pub don’t try to process it. For example:

    environment:
      sdk: '>=1.8.3 <3.0.0'