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) {}
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。