Why in Pubspec.lock flutter sdk is under version: "0.0.0"? How to safely lock a flutter version?

Viewed 1235

I was helping to debug a test game app. I had a deep dive in packages. One thing that i am still puzzled about and cannot find proper documentation on stack overflow and official documentation... is the lines of codes that display flutter version: "0.0.0" while it is obviously not.

In pubspec.lock all the packages are properly up-to-date like this one:

   dependency: "direct main"
   description:
     name: audioplayers
     url: "https://pub.dartlang.org"
   source: hosted
   version: "0.14.2"

But is not for flutter

    dependency: "direct main"
    description: flutter
    source: sdk
    version: "0.0.0" 
...
flutter_test:
    dependency: "direct dev"
    description: flutter
    source: sdk
    version: "0.0.0"
  flutter_web_plugins:
    dependency: transitive
    description: flutter
    source: sdk
    version: "0.0.0"

then at the very bottom of there is

sdks:
  dart: ">=2.6.0 <3.0.0"
  flutter: ">=1.12.13+hotfix.4 <2.0.0"

Also in pubspec.yaml

Dart is constrained this way

  sdk: ">=2.3.0 <3.0.0"

while flutter is not

dependencies:
  flutter:
    sdk: flutter

Confused

We compared our code to different source code on github and saw similar behaviors. For example: https://github.com/japalekhin/langaw/blob/master/pubspec.lock

https://github.com/fireship-io/183-flutter-draggable-game/blob/master/pubspec.lock

  • To fix a version of flutter - can we edit the pubspec.lock line at the bottom? Would that create instability?
  • Any documentation, explanations about what is happening under the hood? and why having a version: "0.0.0" in the code?
1 Answers

You can specify the constraints of the Flutter SDK itself in the environment section as explained in the Pubspec Doc.

As of writing this answer I am on Flutter version 2.0.3.
After creating the template project using flutter create myapp, pubspec.yaml and pubspec.lock files didn't have Flutter SDK constraint.

I added the Flutter SDK constraint as below -

environment:
  sdk: ">=2.7.0 <3.0.0"
  flutter: '2.0.3'

Executing flutter pub get command, updated the pubspec.lock file as below -

sdks:
  dart: ">=2.12.0-0.0 <3.0.0"
  flutter: ">=2.0.3"

Even after specifying Flutter SDK constraint in exact syntax, the updated pubspec.lock file has the lower bound constraint instead of the range constraint. That's strange.

Also, specifying the caret syntax as below generates the same constraints as above -

environment:
  sdk: ">=2.7.0 <3.0.0"
  flutter: '^2.0.3'

I got leads from this issue.

Related