avoid_empty_else
Details about the 'avoid_empty_else' diagnostic produced by the Dart analyzer.
Empty statements are not allowed in an 'else' clause.
Description
#
The analyzer produces this diagnostic when the statement after an else
is an empty statement (a semicolon).
For more information, see the documentation for
avoid_empty_else.
Example
#
The following code produces this diagnostic because the statement
following the else is an empty statement:
void f(int x, int y) {
if (x > y)
print("1");
else ;
print("2");
}
Common fixes
#
If the statement after the empty statement is intended to be executed only
when the condition is false, then remove the empty statement:
void f(int x, int y) {
if (x > y)
print("1");
else
print("2");
}
If there is no code that is intended to be executed only when the
condition is false, then remove the whole else clause:
void f(int x, int y) {
if (x > y)
print("1");
print("2");
}
除非另有说明,文档之所提及适用于 Dart 3.10.3 版本报告页面问题.