prefer_initializing_formals
Use an initializing formal to assign a parameter to a field.
Description
#The analyzer produces this diagnostic when a constructor parameter is used to initialize a field without modification.
Example
#The following code produces this diagnostic because the parameter c
is
only used to set the field c
:
dart
class C {
int c;
C(int c) : this.c = c;
}
Common fixes
#Use an initializing formal parameter to initialize the field:
dart
class C {
int c;
C(this.c);
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。