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
除非另有说明,文档之所提及适用于 Dart 3.5.0 版本,本页面最后更新时间: 2024-09-22。 查看文档源码 或者 报告页面问题。