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;
}
Unless stated otherwise, the documentation on this site reflects Dart 3.7.3. Page last updated on 2025-05-08. View source or report an issue.