Undefined getter for extensionDRT-W1659
The analyzer produces this diagnostic when an extension override is used to invoke a getter, but the getter isn't defined by the specified extension. The analyzer also produces this diagnostic when a static getter is referenced but isn't defined by the specified extension.
Examples
The following code produces this diagnostic because the extension E
doesn't declare an instance getter named b
:
extension E on String {
String get a => 'a';
}
extension F on String {
String get b => 'b';
}
void f() {
E('c').b;
}
The following code produces this diagnostic because the extension E
doesn't declare a static getter named a
:
extension E on String {}
var x = E.a;
Common fixes
If the name of the getter is incorrect, then change it to the name of an existing getter:
extension E on String {
String get a => 'a';
}
extension F on String {
String get b => 'b';
}
void f() {
E('c').a;
}
If the name of the getter is correct but the name of the extension is wrong, then change the name of the extension to the correct name:
extension E on String {
String get a => 'a';
}
extension F on String {
String get b => 'b';
}
void f() {
F('c').b;
}
If the name of the getter and extension are both correct, but the getter isn't defined, then define the getter:
extension E on String {
String get a => 'a';
String get b => 'z';
}
extension F on String {
String get b => 'b';
}
void f() {
E('c').b;
}