body_might_complete_normally_catch_error
This 'onError' handler must return a value assignable to '{0}', but ends without returning a value.
Description
#The analyzer produces this diagnostic when the closure passed to the
onError
parameter of the Future.catchError
method is required to
return a non-null
value (because of the Future
s type argument) but can
implicitly return null
.
Example
#The following code produces this diagnostic because the closure passed to
the catchError
method is required to return an int
but doesn't end
with an explicit return
, causing it to implicitly return null
:
void g(Future<int> f) {
f.catchError((e, st) {});
}
Common fixes
#If the closure should sometimes return a non-null
value, then add an
explicit return to the closure:
void g(Future<int> f) {
f.catchError((e, st) {
return -1;
});
}
If the closure should always return null
, then change the type argument
of the Future
to be either void
or Null
:
void g(Future<void> f) {
f.catchError((e, st) {});
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。