avoid_ returning_ null_ for_ void
Don't return 'null' from a function with a return type of 'void'.
Don't return 'null' from a method with a return type of 'void'.
Description
#
The analyzer produces this diagnostic when a function that has a return
type of
void
explicitly returns
null
.
Example
#
The following code produces this diagnostic because there is an explicit
return of
null
in a
void
function:
void f() {
return null;
}
Common fixes
#Remove the unnecessary explicit null
:
void f() {
return;
}
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Page last updated on 2025-9-1. View source or report an issue.