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:
Null f() {}
Future<Null> f() {}
Stream<Null> f() {}
f(Null x) {}
GOOD:
void f() {}
Future<void> f() {}
Stream<void> f() {}
f(void x) {}
Some exceptions include formulating special function types:
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:
<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:
linter:
rules:
- prefer_void_to_null
Unless stated otherwise, the documentation on this site reflects Dart 3.6.0. Page last updated on 2024-07-03. View source or report an issue.