Dart 2.12 release — Null Safety

Take a look at Dart null safety and learn how to migrate your Flutter project to it.

Evan Fang

--

March 3, 2021: 2.12 release

This section lists notable changes made from October 2, 2020, through March 3, 2021. For details about the 2.12 release, see Announcing Dart 2.12.

Just few days ago, Dart 2.12 finally released. One of it’s cool features is null safety, which is a life saver for all Flutter developers.

Null safety is a very powerful feature that can prevent your app from NullPointException. You can clearly declare whether a variable can be null or not. Then handle the null case if it is nullable; otherwise, just use it directly.

Table of contents

  1. Overview: Sound null safety
  2. Migrating your Flutter project to null safety
  3. Using the migration tool

Overview: Sound null safety

The official documentation contains a very clear explanation about null safety.

If you have learned Swift or Kotlin before, you must be familiar with null safety. Dart null safety is kinda like what Swift or Kotlin does, with only small differences in syntax. So I’m not going to describe lots about it. Please refer to the documentation for more information. Let’s focus on how to migrate our project to a null safety version.

Migrating your Flutter project to null safety

Let’s create a whole new Flutter project as an example.

Switch to a Dart 2.12 release

First of all, you need to switch Flutter beta channel to get the latest Dart version. For now, it is Dart 2.12.0.

flutter channel beta
flutter upgrade

Change SDK constrains over 2.12

--

--

Evan Fang

An Android/Flutter engineer at LINE Corporation.