unnecessary_ breaks
Details about the 'unnecessary_breaks' diagnostic produced by the Dart analyzer.
Unnecessary 'break' statement.
Description
#
The analyzer produces this diagnostic when a
break statement appears at the end of a non-empty
switch case or default clause. In Dart 3.0 and later, switch
cases don't fall through to the next case, so a
break at the end of a non-empty case body is
redundant.
Example
#
The following code produces this diagnostic because the
break is at the end of a non-empty
case body:
void f(int x) {
switch (x) {
case 1:
print('one');
break;
case 2:
print('two');
}
}
Common fixes
#Remove the break statement:
void f(int x) {
switch (x) {
case 1:
print('one');
case 2:
print('two');
}
}
除非另有说明,文档之所提及适用于 Dart 3.12.2 版本报告页面问题.