prefer_const_constructors

Group: style

Maturity: stable

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

Since info is static, may be stale

View all Lint Rules

Using the Linter

PREFER using const for instantiating constant constructors.

If a const constructor is available, it is preferable to use it.

GOOD:

class A {
  const A();
}

void accessA() {
  A a = const A();
}

GOOD:

class A {
  final int x;

  const A(this.x);
}

A foo(int x) => new A(x);

BAD:

class A {
  const A();
}

void accessA() {
  A a = new A();
}