What does “non-nullable by default” mean in Dart?

Technology CommunityCategory: FlutterWhat does “non-nullable by default” mean in Dart?
VietMX Staff asked 3 years ago
  • Non-nullable by default means that any variable that is declared normally cannot be null.
  • Any operation accessing the variable before it has been assigned is illegal.
  • Additionally, assigning null to a non-nullable variable is also not allowed.
void main() {
  String word;
  print(word); // illegal

  word = 'Hello, ';
  print(word); // legal
}
void main() {
  String word;

  word = null; // forbidden
  world = 'World!'; // allowed
}