3

I recently migrated one project to null-safety (From Flutter SDK 2.2.3 to 2.8.1), but I have some more code in same project coded without null-safety on different branch in my git. Now I want to migrate that code. But I am not able to do it with dart migrate command(because it shows lots of analytical errors which can take a lot of time to solve manually)

So my question is how can I migrate that code with dart migrate command (Dart Migration Tool).

Can anyone provide a solution to this?

Milan Surelia
  • 884
  • 1
  • 8
  • 18
  • Please let me know if my answer helped you out. If so, I would appreciate if you could accept my answer :) If you still have questions, feel free to ask :) – Jahn E. Jan 25 '22 at 10:33
  • @JahnE. As you said that I can opt out files in migration tool. But I am facing totally different problem. I migrated whole project code to null safety. My Problem is: I have some of the code in different branch & while migrating it to null safety, it raises errors to add null Check operators in the code. For that I can't use Migration Tool. I am seeking a solution for this. – Milan Surelia Jan 31 '22 at 12:29
  • Add a language version comment to the top of any Dart files that you don’t want to consider during your current migration: `// @dart=2.9` (see unsound nullsafety). It doesnt matter in which branch you are, you can still use the migration tool (or do it by hand as described in the article) once you checked out a specific branch, just add the annotation manually, I dont see a problem there. – Jahn E. Jan 31 '22 at 14:05

1 Answers1

0

Question 1: Is there any way to migrate specific set of files from Flutter Project's code to null safety?

Yes you have the option to opt out certain files, which is usually done for larger projects where migration to nullsafety is a more time consuming task.

This concept is referred to as unsound null safety, please learn more about here.

In the migration guide, you can see how to opt out files when using the migration tool:

Opting out files:

Although we recommend migrating all at once, sometimes that isn’t practical, especially in a large app or package. To opt out a file or directory, click its green checkbox. Later, when you apply changes, each opted out file will be unchanged except for a 2.9 version comment.

Question 2: How can I migrate code with dart migrate command (Dart Migration Tool).

The migration guide (linked above) provides you with all relevant information, as well as a video tutorial.

Since you want to use the migration tool, you can simply uncheck files on the left hand side (see blogquote above) and later, when you apply the changes these unchecked files will not be changed.

Once you have time to update other files, re-run the migration tool and simply update all remaining (or specific) files until you completely migrated each file of your package.

Note: If you have any questions on how to test or run mixed-version programs (due to unsound-nullsafety, which is the case if you do not migrate the entire package at once), check this link.

Jahn E.
  • 1,228
  • 3
  • 6
  • 21