initialize_ in_ field_ declaration
Details about the 'initialize_in_field_declaration' diagnostic produced by the Dart analyzer.
Field should be initialized in the field declaration.
Description
#The analyzer produces this diagnostic when a field initialized in either the initializer list or body of a primary constructor can be initialized in the field declaration.
Example
#
The following code produces this diagnostic because the field y is
initialized in the primary constructor's initializer list, when it can be
initialized in the field declaration:
class C(int x) {
this : y = x;
int y;
}
Common fixes
#Initialize the field in its declaration:
class C(int x) {
int y = x;
}
Unless stated otherwise, the documentation on this site reflects Dart 3.12.2. Report an issue.