📱 Flutter
Beginner
What is null safety in Dart?
Answer
Null safety, introduced in Dart 2.12, is a type system feature that makes all types non-nullable by default. This means the Dart compiler guarantees that a variable of type String will never contain null, eliminating an entire class of runtime null-reference errors. To allow null, you explicitly opt in with a ? suffix: String? name. The compiler then forces you to handle the null case before accessing the value, making code more robust and self-documenting.