Dart Analyze logoDart Analyze/
DRT-W1481

Implicit return at the end of function or methodDRT-W1481

Major severityMajor
Bug Risk categoryBug Risk

Any function or method that doesn't end with either an explicit return or a throw implicitly returns null. This is rarely the desired behavior. The analyzer produces this diagnostic when it finds an implicit return.

Example

The following code produces this diagnostic because f doesn't end with a return:

int f(int x) {
  if (x < 0) {
    return 0;
  }
}

Common fixes

Add a return statement that makes the return value explicit, even if null is the appropriate value.