I want to upgrade my flutter to get new features such as null safety, but I didn't want my previous project to affect them. I want new changes only for my new flutter project, I want to run my old project similar to the old way. Is there any way? Please guide me through it.
Thank You
Adding null safety to Dart and Flutter became a good solution to developer productivity issues and reduced the number of bugs. With null safety, now Flutter developers can specify which variables can be null and all the previously unnoticed errors will show up during static analysis.
Enabling null safety Sound null safety is available in Dart 2.12 and Flutter 2.
Setting SDK constraints in your old project's pubspec.yaml
file should be enough.
For example, the following, does not have null safety enabled:
environment:
sdk: ">=2.11.0 <3.0.0"
You can also specify at the top of your Dart file to disable null checks for that file.
// @dart=2.9
The above answer wasn't working for me after I upgraded to Dart v2.12
on the beta
channel. So I found these options:
You can add this to the top of any dart file to disable null-safety checks.
// @dart=2.9
or similar to the answer above, I had to include a version prior to 2.12 to disable null safety. You would edit this line in the pubspec.yaml
file.
environment:
sdk: ">=2.11.0 <3.0.0"
You can run flutter project without null safety with --no-sound-null-safety
option with flutter run
.
Also you can add this as an argument in launch.json
in VSCode
"configurations": [
{
"name": "Flutter",
"request": "launch",
"type": "dart",
"flutterMode": "debug",
"args": [
"--no-sound-null-safety"
],
},
]
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