empty_statements
Unnecessary empty statement.
Description
#The analyzer produces this diagnostic when an empty statement is found.
Example
#The following code produces this diagnostic because the statement controlled by the while
loop is an empty statement:
void f(bool condition) {
while (condition);
g();
}
void g() {}
Common fixes
#If there are no statements that need to be controlled, then remove both the empty statement and the control structure it's part of (being careful that any other code being removed doesn't have a side-effect that needs to be preserved):
void f(bool condition) {
g();
}
void g() {}
If there are no statements that need to be controlled but the control structure is still required for other reasons, then replace the empty statement with a block to make the structure of the code more obvious:
void f(bool condition) {
while (condition) {}
g();
}
void g() {}
If there are statements that need to be controlled, remove the empty statement and adjust the code so that the appropriate statements are being controlled, possibly adding a block:
void f(bool condition) {
while (condition) {
g();
}
}
void g() {}
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.