prefer_const_constructors_in_immutables
Prefer declaring const
constructors on @immutable
classes.
This rule is available as of Dart 2.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
Unless stated otherwise, the documentation on this site reflects Dart 3.5.3. Page last updated on 2024-07-03. View source or report an issue.