implicit_this_reference_in_initializer
The instance member '{0}' can't be accessed in an initializer.
Description
#The analyzer produces this diagnostic when it finds a reference to an instance member in a constructor's initializer list.
Example
#The following code produces this diagnostic because defaultX
is an instance member:
class C {
int x;
C() : x = defaultX;
int get defaultX => 0;
}
Common fixes
#If the member can be made static, then do so:
class C {
int x;
C() : x = defaultX;
static int get defaultX => 0;
}
If not, then replace the reference in the initializer with a different expression that doesn't use an instance member:
class C {
int x;
C() : x = 0;
int get defaultX => 0;
}
Unless stated otherwise, the documentation on this site reflects Dart 3.7.3. Page last updated on 2025-05-08. View source or report an issue.