getter_ not_ subtype_ setter_ types
The return type of getter '{0}' is '{1}' which isn't a subtype of the type '{2}' of its setter '{3}'.
Description
#The analyzer produces this diagnostic when the return type of a getter isn't a subtype of the type of the parameter of a setter with the same name.
The subtype relationship is a requirement whether the getter and setter are in the same class or whether one of them is in a superclass of the other.
Example
#
The following code produces this diagnostic because the return type of the
getter
x
is
num
, the parameter type of the setter
x
is
int
, and
num
isn't a subtype of
int
:
class C {
num get x => 0;
set x(int y) {}
}
Common fixes
#If the type of the getter is correct, then change the type of the setter:
class C {
num get x => 0;
set x(num y) {}
}
If the type of the setter is correct, then change the type of the getter:
class C {
int get x => 0;
set x(int y) {}
}
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Page last updated on 2025-9-4. View source or report an issue.