unreachable_ switch_ case
This case is covered by the previous cases.
Description
#
The analyzer produces this diagnostic when a
case
clause in a
switch
statement doesn't match anything because all of the matchable values are
matched by an earlier
case
clause.
Example
#
The following code produces this diagnostic because the value
1
was
matched in the preceding case:
void f(int x) {
switch (x) {
case 1:
print('one');
case 1:
print('two');
}
}
Common fixes
#Change one or both of the conflicting cases to match different values:
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.9.2. Page last updated on 2025-9-1. View source or report an issue.