avoid_init_to_null

Group: style

Maturity: stable

Dart SDK: >= 2.0.0 • (Linter v0.1.11)

flutter pedantic

View the Project on GitHub dart-lang/linter

From effective dart:

DON'T explicitly initialize variables to null.

In Dart, a variable or field that is not explicitly initialized automatically gets initialized to null. This is reliably specified by the language. There's no concept of "uninitialized memory" in Dart. Adding = null is redundant and unneeded.

GOOD:

int _nextId;

class LazyId {
  int _id;

  int get id {
    if (_nextId == null) _nextId = 0;
    if (_id == null) _id = _nextId++;

    return _id;
  }
}

BAD:

int _nextId = null;

class LazyId {
  int _id = null;

  int get id {
    if (_nextId == null) _nextId = 0;
    if (_id == null) _id = _nextId++;

    return _id;
  }
}