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:
dart
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:
dart
void f(int x) {
switch (x) {
case 1:
print('one');
case 2:
print('two');
}
}
Was this page's content helpful?
Thank you for your feedback!
Provide details Thank you for your feedback! Please let us know what we can do to improve.
Provide details Unless stated otherwise, the documentation on this site reflects Dart 3.8.1. Page last updated on 2025-05-08. View source or report an issue.