flutterdartsdkpubspec.yaml

Flutter Run Error: SDK Constraint Must Be >=2.12.0 for Null Safety


I'm encountering an error when trying to run my Flutter project. The error message is as follows:

Resolving dependencies...
The lower bound of "sdk: '>=2.7.0 <3.0.0'" must be 2.12.0 or higher to enable null safety.
The current Dart SDK (3.5.0) only supports null safety.
For details, see https://dart.dev/null-safety

I checked my pubspec.yaml file, and the SDK constraint is set to >=2.7.0 <3.0.0. I am using Dart SDK version 3.5.0.

How can I resolve this SDK constraint issue? Should I update the SDK constraint in pubspec.yaml? If so, what should it be changed to?

I want to ensure my project is compatible with null safety. Any guidance on migrating to null safety would also be appreciated.

Thank you!


Solution

  • in your pubspec.yaml file, change your sdk setting to this:

    environment:
      sdk: ^3.5.0