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

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


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.