prefer_void_to_null
Don't use the Null type, unless you are positive that you don't want void.
This rule is available as of Dart 2.1.
This rule has a quick fix available.
Details
#DON'T use the type Null where void would work.
BAD:
dart
Null f() {}
Future<Null> f() {}
Stream<Null> f() {}
f(Null x) {}
GOOD:
dart
void f() {}
Future<void> f() {}
Stream<void> f() {}
f(void x) {}
Some exceptions include formulating special function types:
dart
Null Function(Null, Null);
and for making empty literals which are safe to pass into read-only locations for any type of map or list:
dart
<Null>[];
<int, Null>{};
Usage
#To enable the prefer_void_to_null
rule,
add prefer_void_to_null
under linter > rules in your
analysis_options.yaml
file:
analysis_options.yaml
yaml
linter:
rules:
- prefer_void_to_null
除非另有说明,文档之所提及适用于 Dart 3.5.4 版本,本页面最后更新时间: 2024-08-02。 查看文档源码 或者 报告页面问题。