Skip to content

[Solved][Flutter] This requires the ‘non-nullable’ language feature to be enabled. Try updating your pubspec.yaml to set the minimum SDK constraint to 2.12.0 or higher, and running ‘pub get’.

The code after the dart version upgrade needs to enable the so-called Null-Safety to compile. If the code disable Null-Safety, the following error will occur:

This requires the 'non-nullable' language feature to be enabled. Try updating your pubspec.yaml to set the minimum SDK constraint to 2.12.0 or higher, and running 'pub get'.

Solution: Enable Null-Safety

1. Confirm your Dart version (in my example, it needs to be at least 2.12)

dart --version


If the version is too low, you need to upgrade to the minimum version required.



2. Use the following commands to confirm the package’s requirement

dart pub upgrade --null-safety
dart pub get
dart pub outdated --mode=null-safety



3. Migration

If there is an error, it means there is a library and the package does not support Null-Safety.

dart pub outdated --mode=null-safety

References


Read More

Tags:

1 thought on “[Solved][Flutter] This requires the ‘non-nullable’ language feature to be enabled. Try updating your pubspec.yaml to set the minimum SDK constraint to 2.12.0 or higher, and running ‘pub get’.”

  1. The current Dart SDK version is 3.1.0.

    Because pizzaflutterapp depends on cupertino_icons >=0.1.1 <1.0.1 which doesn't support null safety, version solving failed.

    The lower bound of "sdk: '=2.0.0-dev.28.0 <3.0.0'" must be 2.12.0 or higher to enable null safety.
    For details, see https://dart.dev/null-safety

    You can try the following suggestion to make the pubspec resolve:
    * Try upgrading your constraint on cupertino_icons: flutter pub add cupertino_icons:^1.0.6

Leave a Reply