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');
}
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。