What is it?
Null safety is the guarantee within an object-oriented programming language that the object references will never have null values.
That translates into 0 "chances" of getting a null reference error. So no more unexpected application crashes caused by this "billion-dollar mistake", as Tony Hoare called the invention of the null pointer.
Currently, JetBrain’s Kotlin and Apple’s Swift are the ones of the most popular programming languages that use null-safe types by default. Soon, Google’s Dart will join the select club.
How will it work?
The types in our code will be considered non-nullable by default. This means that values can’t be null unless specifically marked by us as nullable.
With this, our runtime null-dereference errors turn into edit-time analysis errors and the Dart analyzer can enforce some good practices. For example, it can make sure we check for null before reading a nullable variable.
Also, the Dart compilers and runtimes can optimize away internal null checks, so apps can be faster and smaller.
When will it happen?
Most probably in early 2021, in the 2.12 release of Dart.
The previous releases already introduced a number of breaking changes that prepare this upcoming language feature.
It can be tested right now with a DartPad version that uses the 2.12 dev release, or in your environment if you switch to using that Dart release yourself.
Null safety is still in beta, so don’t use null safety in production code.
After the production release, it will take some time to migrate all packages and code to be null safe compliant. The best guess is that until the release of Dart 3.0 running in mixed mode will still be allowed.
Currently, using the master channel of Flutter to run your app, you’ll get a
Running with unsound null safety warning.
Running with unsound null safety
For more information see…