switch_ case_ completes_ normally
The 'case' shouldn't complete normally.
Description
#
The analyzer produces this diagnostic when the statements following a
case
label in a
switch
statement could fall through to the next
case
or
default
label.
Example
#
The following code produces this diagnostic because the
case
label with
a value of zero (0
) falls through to the
default
statements:
void f(int a) {
switch (a) {
case 0:
print(0);
default:
return;
}
}
Common fixes
#
Change the flow of control so that the
case
won't fall through. There
are several ways that this can be done, including adding one of the
following at the end of the current list of statements:
- a
return
statement, - a
throw
expression, - a
break
statement, - a
continue
, or - an invocation of a function or method whose return type is
Never
.
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Page last updated on 2025-9-1. View source or report an issue.