pubspec.yaml has no lower-bound SDK constraint

40k views Asked by At

I was taking MDC101 flutter code lab. I cloned the starter project from the git repository as per the instructions but after clonning done, I executed flutter pub get and it gave me the following error.

pubspec.yaml has no lower-bound SDK constraint.
You should edit pubspec.yaml to contain an SDK constraint:
environment:
  sdk: '>=2.10.0 <3.0.0'
6

There are 6 answers

0
Feroz Khan On BEST ANSWER

As per the error instructions I added the following in my pubspec.yaml

environment:
  sdk: '>=2.10.0 <3.0.0'

And then I executed flutter pub get and it's working fine now.

0
Paulo Belo On

As of Dart 2.12, omitting the SDK constraint is an error. When the pubspec has no SDK constraint, pub get fails with a message like the following:

pubspec.yaml has no lower-bound SDK constraint.
You should edit pubspec.yaml to contain an SDK constraint:
(...)

For example, the following constraint says that this package works with any Dart SDK that’s version 2.10.0 or higher:

environment:
  sdk: '>=2.10.0 <3.0.0'

For more information you can check the docs

0
elhoucine ayoub On

Check your flutter channel with command line :

flutter channel

if it is in master channel then switch to stable channel with :

flutter channel stable

4
Joel G Mathew On

If you received this error even when your pubspec.yaml file contained the correct sdk line, be sure to check subfolders in your main folder. This was noted to happen while doing a flutter packages get from the font_awesome_flutter package. The reason was that even though the main pubspec.yaml contained the correct line, there was an offending example/pubspec.yaml. Add the lines to that file:

environment:
  sdk: ">=2.7.0 <3.0.0"

Referenced issue.

1
Alexander On

open the project with lower sdk version and new flutter project copy the start code from the sdk to your new(deleting the startup code) move the asset fold from lower sdk project to new projec, droping it on the new project name open directory of new project delete the mipmap files from app>main>res and move put the ones from the lower sdk do same for iso>Runner>Assets.xcassets

1
Mosawir Shah On

Add the environment: sdk: '>=2.10.0 <3.0.0' to the pubspec.yaml file And press 'ctrl + s' then run the command flutter pub get.