Introduction
Dart is Google's language for building apps, and it is best known as the language of Flutter β the framework that builds apps for phones, web, and desktop from one codebase. But Dart is worth understanding on its own: it is a modern, typed language with one of the clearest approaches to missing values and asynchronous code in any mainstream language.
Sound null safety: the compiler guarantees it
Dart's null safety is "sound": if the compiler says your code is null-safe, it really is β no runtime surprises. Like Kotlin and Swift, Dart marks nullable types with ? :
void main () { String name = "Sara" ; // name = null; // Error: null is not a String String ? nickname = null ; print ( nickname ?. length ); // null, no crash print ( nickname ?? "No nickname" ); // "No nickname" }
Enter fullscreen mode
Exit fullscreen mode
The ?. safe-call operator and ?? fallback operator work exactly as in Kotlin.β¦