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:
dart
class C {
int x;
C() : x = defaultX;
int get defaultX => 0;
}
Common fixes
#If the member can be made static, then do so:
dart
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:
dart
class C {
int x;
C() : x = 0;
int get defaultX => 0;
}
Was this page's content helpful?
Thank you for your feedback!
Provide details Thank you for your feedback! Please let us know what we can do to improve.
Provide details Unless stated otherwise, the documentation on this site reflects Dart 3.8.1. Page last updated on 2025-05-08. View source or report an issue.