Skip to content
Justice Tech School

Dart Null Safety

Types are non nullable by default. Add ? to allow null. Use ?. for safe access, ?? for a default, ! to assert non null and late for delayed initialisation.

Example
String? name;
print(name ?? "unknown");
print(name?.length);
name = "Ada";
print(name.length);

Exercise

Allow null.

String s;

Quiz Test

What does String? mean?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.