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');
}
}
Unless stated otherwise, the documentation on this site reflects Dart 3.7.3. Page last updated on 2025-05-08. View source or report an issue.