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() {}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。