return_of_invalid_type_from_closure
The returned type '{0}' isn't returnable from a '{1}' function, as required by the closure's context.
Description
#The analyzer produces this diagnostic when the static type of a returned expression isn't assignable to the return type that the closure is required to have.
Example
#The following code produces this diagnostic because f
is defined to be a
function that returns a String
, but the closure assigned to it returns an
int
:
dart
String Function(String) f = (s) => 3;
Common fixes
#If the return type is correct, then replace the returned value with a value of the correct type, possibly by converting the existing value:
dart
String Function(String) f = (s) => 3.toString();
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。