Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

pub get says the SDK lower bound must be 2.12.0 or higher

ErrorThe lower bound of "sdk: '>=2.1.0 <3.0.0'" must be 2.12.0 or higher to enable null safety.

Short answer

Dart 3 only runs sound null safety, so any package whose sdk constraint starts below 2.12.0 is refused. Find whether the constraint is in your own pubspec.yaml or a dependency's. Migrate your code to null safety, or upgrade the dependency to a release that supports it.

  • Applies to Dart 3.x, Flutter 3.3x
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Read the package name in the error. If it is your own app, the constraint is in your pubspec.yaml. If it is another package, find who depends on it.

    dart pub get
    dart pub deps | head -60
  2. 2Match what you see, then jump to its fix

    1. 1The error names your own package, and pubspec.yaml has sdk: '>=2.1.0 <3.0.0' or similarYour own pubspec.yaml still has a pre-null-safety constraintFix
    2. 2The error names a package from pub.dev that you did not writeA dependency was never updated for null safetyFix
    3. 3The language version must be >=2.12.0, or Library doesn't support null safetyA file or package opts out with an old language versionFix

What does the error look like?

  • The lower bound of "sdk: '>=2.1.0 <3.0.0'" must be 2.12.0 or higher to enable null safety.
  • The language version must be >=2.12.0
  • Library doesn't support null safety

Cause 1 of 3

Your own pubspec.yaml still has a pre-null-safety constraint

1Check

Open the environment section of the project's pubspec.yaml and read the sdk line.

grep -n -A3 '^environment' pubspec.yaml

2Fix

Dart 3 cannot run code that is not null safe. Migrate the app with a Dart 2.19 SDK (the migration tool was removed in Dart 3), then raise the lower bound to 2.12.0 or higher.

environment:
  sdk: '>=3.0.0 <4.0.0'

3Verify

Run pub get and the analyzer.

dart pub get
dart analyze

Confirmed by dart.dev

Did this fix it?

Cause 2 of 3

A dependency was never updated for null safety

1Check

Find which dependency pulls it in and whether a newer version exists.

dart pub deps
dart pub outdated

2Fix

Upgrade first. If that is not enough, allow major version upgrades, then fix what the analyzer reports. If a package has no null safe release, replace it.

dart pub upgrade
dart pub upgrade --major-versions
dart analyze

3Verify

pub get resolves and the analyzer is clean.

dart pub get && dart analyze

Confirmed by dart.dev

Did this fix it?

Cause 3 of 3

A file or package opts out with an old language version

1Check

Search the code for a language version comment at the top of files, and for a languageVersion override in package config.

grep -rn "@dart" lib test bin 2>/dev/null

2Fix

Remove the override and make the file null safe; a language version below 2.12 is not accepted in Dart 3.

// delete lines such as:
// @dart=2.9

3Verify

Analyze the project again.

dart analyze

Confirmed by dart.dev

Did this fix it?

How do I stop it coming back?

  • Keep dependencies current with dart pub outdated before each Flutter upgrade.
  • Before choosing a package, check on pub.dev that it supports Dart 3.
  • Set a lower bound of 3.0.0 or higher in new projects.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.