undefined_ instance_ member_ read
Details about the 'undefined_instance_member_read' diagnostic produced by the Dart analyzer.
The member '{0}' is declared in '{1}', but private names are visible only in their own library.
The member '{0}' isn't defined for the type '{1}'.
There's a setter '{0}' for the type '{1}', but no getter.
Description
#The analyzer produces this diagnostic when an instance member is read, invoked, or torn off, but neither the static type of the receiver nor any applicable extension has an accessible method, getter, or field with that name.
Examples
#
The following code produces this diagnostic because String doesn't
have a member named len:
int f(String s) => s.len;
The following code produces this diagnostic because List<int> doesn't
have a member named middleIndex:
int f(List<int> l) => l.middleIndex();
The following code produces this diagnostic because C has only a
setter named x, which can't be read:
class C {
set x(int _) {}
}
int f(C c) => c.x;
Common fixes
#If the member you intend to use has a different name, then change the name to match:
int f(String s) => s.length;
If the member is declared in an extension that isn't imported, then import the library that declares the extension.
If the member isn't defined, then define it in the type of the receiver or in an extension that applies to that type:
extension on List<int> {
int middleIndex() => length ~/ 2;
}
int f(List<int> l) => l.middleIndex();
If the type has only a setter, then add a getter with the same name:
class C {
int get x => 0;
set x(int _) {}
}
int f(C c) => c.x;
Unless stated otherwise, the documentation on this site reflects Dart 3.13.3. Report an issue.