How to enable Null-Safety on Flutter without breaking the project?

Asked

Viewed 101 times

2

How to enable Null-Safety in Flutter without running the risk of breaking the project?

I saw many reports of people that when enabling appear compatibility problems in certain libraries.

environment:
  sdk: ">=2.11.0 <3.0.0"

1 answer

2


Unfortunately, some third-party libraries have not yet been upgraded to Null-Safety, which causes the project to break. But there is a process that can be done in a way to minimize the chances of this occurring.

Through the terminal, execute the following command:

dart pub outdated --mode=null-safety

This command will list all the packages in your project and whether there is a Null-Safety compatible version. Check that all packages in your project already have compatible versions, and if so, simply run the following commands to update the pubsec.yaml file and use the respective versions of the packages:

dart pub upgrade --null-safety
dart pub get

With the package upgrade, some fixes may be required, so do this first before continuing. After fixed, run the following command to migrate your project to Null-Safety:

dart migrate

Important: If you have a library that doesn’t already have Null-Safety support, see if there is an Issue open in the Git repository and recent discussions, in this case, wait for the update, or, if the package has become discontinued (it hasn’t received updates for a long time), consider changing it for a similar one that supports Null-Safety.

  • Source: https://dart.dev/null-safety/migration-guide

Browser other questions tagged

You are not signed in. Login or sign up in order to post.