Null safety is one of Dart's most important features. By default, it stops a variable from ever becoming null. It catches the 'using a value that doesn't exist' problem — the kind that crashes apps — early.
dart
void main() {
String name = 'Dart';
// name = null; // Error: non-nullable variable
String? nickname;
nickname = null;
print(name.length);
print(nickname?.length ?? 0);
}String name can never be null. String? is nullable — it can be null. ?. only accesses the property if a value exists, and ?? provides a default value when it's null.
You should see
4 0