- Introduction
- Basics
- App1 : Elon Musk’s Resume
- App2 : 5K Quotes
- App3 : Calculator
- App4_v1 : Flags Quiz
- Running Apps On Different Devices
- Debbuging
- App5 : Yacht Charter
- App6_v1 : My Books
- Creating responsive and adaptive apps
- App6_v2: My Books
- App7 : Short Vacation
- App8 : Movie Time
- App9 : Schedule Planner
- Shared Preferences
- App10 : Local Weather
- App11 : Discover Tunisia
Sound null safety
The Dart language now supports sound null safety!
When you opt into null safety, types in your code are non-nullable by default, meaning that variables can’t
contain null unless you say they can. With null safety, your runtime null-dereference errors turn into edit-time
analysis errors.
With null safety, all of the variables in the following code are non-nullable:
// 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();
To indicate that a variable might have the value null, just add ? to its type declaration:
aNullableInt
=
null;
Null safety principles
Dart null safety support is based on the following three core design principles:
- Non-nullable by default.
- Incrementally adoptable.
- Fully sound.
Unless you explicitly tell Dart that a variable can be null, it’s considered non-nullable. This default was chosen after research found that non-null was by far the most common choice in APIs.
You choose what to migrate to null safety, and when. You can migrate incrementally, mixing null-safe and non-null-safe code in the same project. We provide tools to help you with the migration.
Dart’s null safety is sound, which enables compiler optimizations. If the type system determines that something isn’t null, then that thing can never be null. Once you migrate your whole project and its dependencies to null safety, you reap the full benefits of soundness — not only fewer bugs, but smaller binaries and faster execution.