What is null safety in Dart?

Why Interviewers Ask This

Foundational questions like this help interviewers calibrate the rest of the interview. A confident, accurate answer signals that you have solid Flutter basics — a prerequisite for any developer role.

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.

Common Mistake

Many candidates answer correctly but can't explain the 'why'. Always be prepared to justify your answer with a concrete example or use case from your Flutter experience.