avoid_returning_null_for_void
Avoid returning null
for void
.
This rule is available as of Dart 2.1.
Rule sets: recommended, flutter
This rule has a quick fix available.
Details
#AVOID returning null
for void
.
In a large variety of languages void
as return type is used to indicate that
a function doesn't return anything. Dart allows returning null
in functions
with void
return type but it also allow using return;
without specifying any
value. To have a consistent way you should not return null
and only use an
empty return.
BAD:
void f1() {
return null;
}
Future<void> f2() async {
return null;
}
GOOD:
void f1() {
return;
}
Future<void> f2() async {
return;
}
Usage
#To enable the avoid_returning_null_for_void
rule,
add avoid_returning_null_for_void
under linter > rules in your
analysis_options.yaml
file:
linter:
rules:
- avoid_returning_null_for_void
除非另有说明,文档之所提及适用于 Dart 3.5.4 版本,本页面最后更新时间: 2024-08-02。 查看文档源码 或者 报告页面问题。