Skip to content

[Solved] Error: This requires the null safety language feature, which is experimental. You can enable the experiment using the '--enable-experiment=non-nullable' command line option.

Last Updated on 2021-10-23 by Clay

Today I used the customize icon to create the button when I developing a mobile application with Flutter, I got an error message as follow:

Error: This requires the null safety language feature, which is experimental. You can enable the experiment using the '--enable-experiment=non-nullable' command line option.


Simply put, the used icon file that I imported used the experimental grammar on current SDK version.

The IDE detect the grammar and recommend me to update the SDK version to 2.10.0.


Solution

We have to do the following two steps:

  • Check the Flutter version (If the version is too low, update SDK version not work either)
  • Change the SDK version in pubspec.yaml file


(Optional) Update Flutter version

You can use the following command to update Flutter version:

flutter upgrade


Change SDK version

Add the setting in the pubspec.yaml file:

environment:
  sdk: ">=2.12.0 <3.0.0"

The use the following command:

flutter pub get


Maybe you need to restart IDE to display normally.

At this time, you can execute the program and do not get any error message.


References


Read More

Tags:

Leave a Reply