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');
}
}
Unless stated otherwise, the documentation on this site reflects Dart 3.11.0. Report an issue.