prefer_expression_function_bodies
Unnecessary use of a block function body.
Description
#The analyzer produces this diagnostic when the body of a function consists of a single return statement with an expression.
Example
#The following code produces this diagnostic because the body of f
has a single return statement:
dart
int f() {
return 0;
}
Common fixes
#If the body is complete, then replace the body with an expression body:
dart
int f() => 0;
If the body isn't complete, then add the missing statements.
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.