I had a lot of problems upgrading my project to Flutter 2.0. After I had solved the problems, I decided to write a quick upgrade guide. If you’re interested in Flutter 2.0, read on
- First, to upgrade your Flutter SDK, you need to open your Terminal and run the following command.
flutter upgrade
Copy the code
- The above command will update your SDK in the default channel, if you want to change your channel, you can use this command.
flutter channel <channel>
Copy the code
3. After the upgrade is complete, you should see the following image: Yes, it is as easy as this!
- Running with unsound null safety
What is null safety? What does unsoud mean?
First, let’s look at the definition of null safety. First, it is a technique that states that a variable cannot be null unless it is artificially defined to allow it to be null. It doesn’t seem intuitive to see what the definition is, so let’s take a look at an example:
With null safety, all variables in the code are not allowed to be null, as follows:
// In null-safe Dart, none of these can ever be null.
var i = 42; // Inferred to be an int.
String name = getFileName();
final b = Foo();
Copy the code
What if I wanted to artificially define it to be allowed to be empty? To its variable declaration as follows:
int? aNullableInt = null;
Copy the code
Null safety in Dart follows the following three principles: [1] Non-nullable by default. – It is non-empty unless the developer defines that it is allowed to be empty. [2] Incrementally adoptable. – Incrementally adopt table. That is, you can choose which project to use NULL Safety on and when, or you can use null Safety in some projects and not in others. [3] Fully sound. The use of NULL Safety in Dart is reliable and supports compiler optimization. If the type system determines that a variable is not null, it will never be null during compilation. If you use Null Safety throughout your project, your project will have fewer bugs, smaller binaries, and faster execution.
Therefore, Running with unsound null safety. What does that mean?
It means that the Flutter framework used in our project already supports NULL safety, but our project does not use NULL Safety.
Is that a problem? The answer is no, you can write your code the way you used to write it, debug it the way you used to debug it, and it doesn’t matter.