I just tried the following in DartPad:
void main() {
int? x;
}
and get the following error:
Error compiling to JavaScript:
main.dart:2:6:
Error: This requires the 'non-nullable' experiment to be enabled.
How do I enable that experiment? I am using the Flutter SDK.
Does the experiment support null-safety static analysis already?
The Dart language now supports sound null safety! When you opt into null safety, types in your code are non-nullable by default, meaning that variables can't contain null unless you say they can.
This means that variables are considered non-nullable by default. If you don't give an object null support when you create it, it will never get a null . As a result, you avoid null reference errors in your code.
Add the following line to the analysis_options.yaml
analyzer:
enable-experiment:
- non-nullable
Manually removing pubspec.lock
and running flutter pub get
resolved the problem. In my case it was due to regression.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With