Dart Analyze

Dart Analyze

Community Analyzer

Don't use more than one case with same value DRT-W1022

Bug risk
Major

DON'T use more than one case with same value.

This is usually a typo or changed value of constant.

BAD:

const int A = 1;
switch (v) {
  case 1:
  case 2:
  case A:
  case 2:
}

GOOD:

const int A = 1;
switch (v) {
  case A:
  case 2:
}

NOTE: this lint only reports duplicate cases in libraries opted in to Dart 2.19 and below. In Dart 3.0 and after, duplicate cases are reported as dead code by the analyzer.