Hello Guys How are you all? Hope You all are fine. When I was trying to run my flutter app and suddenly I get the following error in my stack track. Error: This requires the ‘non-nullable’ experiment to be enabled in a flutter. So today Here I come with all possible solutions for this error.
We are providing you all possible solutions to solve this error. let’s start this article without wasting your time.
How Error: This requires the ‘non-nullable’ experiment to be enabled Occurs ?
I am using analyzer with non-nullable types and added this to my analysis_options.yaml
analyzer:
enable-experiment:
- non-nullable
Now I am trying to build in iOS by following command line.
flutter build ios
I get the error message:
lib/main.dart:61:26: Error: This requires the 'non-nullable' experiment to be enabled.
Try enabling this experiment by adding it to the command line when compiling and running.
How to Solve Error: This requires the ‘non-nullable’ experiment to be enabled?
- How to Solve Error: This requires the 'non-nullable' experiment to be enabled?
To Solve Error: This requires the 'non-nullable' experiment to be enabled you just need to cleaning and upgrading the project dependencies again. Run the below command one by one. The second solution is Many times it's as simple as changing the environment in your pubspec.yaml file to update the lower end and For null safety to work, should be this version at least. then run flutter clean and pub get it will work.
- Error: This requires the 'non-nullable' experiment to be enabled
To Solve Error: This requires the 'non-nullable' experiment to be enabled you just need to cleaning and upgrading the project dependencies again. Run the below command one by one. The second solution is Many times it's as simple as changing the environment in your pubspec.yaml file to update the lower end and For null safety to work, should be this version at least. then run flutter clean and pub get it will work.
Solution 1: cleaning and upgrading the project dependencies again
Actually, this problem occurs just after upgrading the Flutter. To solve this error you just need to cleaning and upgrading the project dependencies again. Run the below command one by one.
First of all clean project by running:
flutter clean
Then upgrading the project dependencies:
flutter packages pub upgrade
Then just run,
flutter pub run build_runner build
Solution 2: changing the environment
Manytime it’s as simple as changing the environment in your pubspec.yaml file to update the lower end and For null safety to work, should be this version at least. then run flutter clean and pub get it will work.
environment:
sdk: ">=2.12.0 <3.0.0"
Or
environment:
sdk: ">=2.6.0 <3.0.0"
Or
environment:
sdk: ">=2.7.0 <3.0.0"
Summery
So, It’s All About This Error. I hope this tutorial helps you to Solve your error. Please Comment Below if You stucks anywhere with my code. And please comment below on which solution worked for you. Thank You.
Also Check Out Below Tutorials
- Class AMSupportURLConnectionDelegate is implemented in both
- Failed assertion: line ‘!_debugLocked’: I/flutter (24830): is not true
- Error: This requires the ‘non-nullable’ experiment to be enabled
- RenderFlex children have non-zero flex but incoming height constraints are unbounded
- zsh: command not found: flutter