return_of_invalid_type
A value of type '{0}' can't be returned from the constructor '{2}' because it has a return type of '{1}'.
A value of type '{0}' can't be returned from the function '{2}' because it has a return type of '{1}'.
A value of type '{0}' can't be returned from the method '{2}' because it has a return type of '{1}'.
Description
#The analyzer produces this diagnostic when a method or function returns a value whose type isn't assignable to the declared return type.
Example
#The following code produces this diagnostic because f
has a return type
of String
but is returning an int
:
String f() => 3;
Common fixes
#If the return type is correct, then replace the value being returned with a value of the correct type, possibly by converting the existing value:
String f() => 3.toString();
If the value is correct, then change the return type to match:
int f() => 3;
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。