目錄
目錄

Prefer declaring const constructors on @immutable classes.

This rule is available as of Dart 2.0.0.

Rule sets: flutter

This rule has a quick fix available.

Details

PREFER declaring const constructors on @immutable classes.

If a class is immutable, it is usually a good idea to make its constructor a const constructor.

BAD:

@immutable
class A {
  final a;
  A(this.a);
}

GOOD:

@immutable
class A {
  final a;
  const A(this.a);
}

Usage

To enable the prefer_const_constructors_in_immutables rule, add prefer_const_constructors_in_immutables under linter > rules in your analysis_options.yaml file:

linter:
  rules:
    - prefer_const_constructors_in_immutables