prefer_const_constructor_declarations

SeverityQuick FixOptions
Info

Details

DO declare constructors as const when possible.

Bad
class Point {
  final double x;
  final double y;

  Point(this.x, this.y);

  Point.origin()
      : x = 0,
        y = 0;
}
Good
class Point {
  final double x;
  final double y;

  const Point(this.x, this.y);

  const Point.origin()
      : x = 0,
        y = 0;
}

Usage

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

custom_lint:
  rules:
    - prefer_const_constructor_declarations