目录

prefer_const_constructors_in_immutables

目录

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:

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

GOOD:

dart
@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:

analysis_options.yaml
yaml
linter:
  rules:
    - prefer_const_constructors_in_immutables