Using Null-Safety in new flutter projects only?

Viewed 475

Currently I'm in Dart SDK version 2.10.4 (stable) and flutter 1.22.5 in my old projects. But now for my new projects, I want to use 2.12.0 version that has null-safety. My question is how to upgrade my dart sdk. And if I updated my sdk version, will it affects my old projects? Is it possible to only use dart 2.12.0 sdk version to my new projects?

2 Answers

First, check the dependency status where it checks whether dependencies inside the project are migrated to it.

Get the migration state of your package’s dependencies, using the following command:

dart pub outdated --mode=null-safety

it should give output

enter image description here

The latest column should be in green, if not then upgrade the dependencies of libs and check whether they support it to not.

Finally, Run the below command for migration

dart migrate

You can specify dart and flutter versions constraints in you pubspec.yaml for each project:

environment:
  sdk: '>=2.12.0 <3.0.0'
  flutter: '>=2.0.0'

So answer is yes, you can use new version of sdk with null safety in new projects and don't use it in your old projects. Just specify older version in pubspec for old projects.

In addition I advise you to migrate your old projects to null safety as soon as all of dependencies you used are migrated. Use this guide for it.

Related