Skip to main content

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;
}