pubspec.yaml has no lower-bound SDK constraint
Asked Answered
C

6

18

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'
Celaeno answered 10/2, 2021 at 5:59 Comment(2)
Just add environment: sdk: '>=2.10.0 <3.0.0' to top of dependencies : in pubspec.yamlAbott
I have added environment: sdk: '>=2.10.0 <3.0.0' this line to bottom of pubspec.yaml and issue resolvedDisharmony
C
10

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.

Celaeno answered 10/2, 2021 at 5:59 Comment(0)
Z
39

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.

Zaneta answered 8/3, 2021 at 2:31 Comment(4)
This is one of the problems. Should really be the accepted answer.Saveall
In my case the problem was not related to "font_awesome_flutter" but was a folder "example" from "OneSignal-Flutter-SDK\example" which contained the offending pubspec.yaml.Stephanstephana
Tip: There are two pubspec.yaml files inside a flutter project, one is in the" root "folder, the other is inside" example/ "folder. We have to add this line to both two files.Stedman
where is the example/ folder?News
C
10

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.

Celaeno answered 10/2, 2021 at 5:59 Comment(0)
E
3

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

Elegant answered 28/5, 2021 at 15:56 Comment(0)
A
0

Check your flutter channel with command line :

flutter channel

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

flutter channel stable

Anjanetteanjela answered 28/2, 2021 at 11:3 Comment(0)
J
0

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

Jailhouse answered 15/7, 2023 at 16:49 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Desiredesirea
C
0

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.

Cheka answered 27/2 at 14:26 Comment(1)
Explain your answer for better understanding.Planet

© 2022 - 2024 — McMap. All rights reserved.