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:
dart
void f() {
return null;
}
Common fixes
#Remove the unnecessary explicit null
:
dart
void f() {
return;
}
Was this page's content helpful?
Thank you for your feedback!
Provide details Thank you for your feedback! Please let us know what we can do to improve.
Provide details Unless stated otherwise, the documentation on this site reflects Dart 3.8.1. Page last updated on 2025-05-08. View source or report an issue.