Dart programs often turn a small numeric signal into a clear status label. This example keeps the check count and threshold explicit so the report line stays easy to inspect.

Program

Play the program to choose the failed check count and inspect the service status line.

failedChecks
service_status_model.dart
Replay: real traced execution (multi-file project)
String classify(int failedChecks, int maxAllowed) {
  if (failedChecks <= maxAllowed) {
    return 'ready';
  }
  return 'blocked';
}

void main() {
  var failedChecks = 1;
  var maxAllowed = 0;
  var status = classify(failedChecks, maxAllowed);
  var line = 'api failed=$failedChecks status=$status';
  print(line);
}
String classify(int failedChecks, int maxAllowed) {
  if (failedChecks <= maxAllowed) {
    return 'ready';
  }
  return 'blocked';
}

void main() {
  var failedChecks = 0;
  var maxAllowed = 0;
  var status = classify(failedChecks, maxAllowed);
  var line = 'api failed=$failedChecks status=$status';
  print(line);
}
  1. failedChecks ← 1

    8void main() {9  var failedChecks = 1;10  var maxAllowed = 0;
    values this step1failedChecks
  2. maxAllowed ← 0

    9var failedChecks = 1;10var maxAllowed = 0;11var status = classify(failedChecks, maxAllowed);
    values this step0maxAllowed
  3. call ← classify(1, 0)

    10var maxAllowed = 0;11var status = classify(failedChecks, maxAllowed);12var line = 'api failed=$failedChecks status=$status';
    values this stepclassify(1, 0)call1failedChecks0maxAllowed
  4. if (failedChecks <= maxAllowed)

    1String classify(int failedChecks, int maxAllowed) {2  if (failedChecks <= maxAllowed) {3    return 'ready';
    values this step1failedChecks0maxAllowed
  5. return ← blocked

    4  }5  return 'blocked';6}
    values this stepblockedreturn
  6. status ← blocked

    10var maxAllowed = 0;11var status = classify(failedChecks, maxAllowed);12var line = 'api failed=$failedChecks status=$status';
    values this stepblockedstatus
  7. line ← api failed=1 status=blocked

    11var status = classify(failedChecks, maxAllowed);12var line = 'api failed=$failedChecks status=$status';13print(line);
    values this stepapi failed=1 status=blockedline1failedChecksblockedstatus
  8. print(line);

    12  var line = 'api failed=$failedChecks status=$status';13  print(line);14}
    outputapi failed=1 status=blocked
    values this stepapi failed=1 status=blockedline
  1. failedChecks ← 0

    8void main() {9  var failedChecks = 0;10  var maxAllowed = 0;
    values this step0failedChecks
  2. maxAllowed ← 0

    9var failedChecks = 0;10var maxAllowed = 0;11var status = classify(failedChecks, maxAllowed);
    values this step0maxAllowed
  3. call ← classify(0, 0)

    10var maxAllowed = 0;11var status = classify(failedChecks, maxAllowed);12var line = 'api failed=$failedChecks status=$status';
    values this stepclassify(0, 0)call0failedChecks0maxAllowed
  4. if (failedChecks <= maxAllowed)

    1String classify(int failedChecks, int maxAllowed) {2  if (failedChecks <= maxAllowed) {3    return 'ready';
    values this step0failedChecks0maxAllowed
  5. return ← ready

    2if (failedChecks <= maxAllowed) {3  return 'ready';4}
    values this stepreadyreturn
  6. status ← ready

    10var maxAllowed = 0;11var status = classify(failedChecks, maxAllowed);12var line = 'api failed=$failedChecks status=$status';
    values this stepreadystatus
  7. line ← api failed=0 status=ready

    11var status = classify(failedChecks, maxAllowed);12var line = 'api failed=$failedChecks status=$status';13print(line);
    values this stepapi failed=0 status=readyline0failedChecksreadystatus
  8. print(line);

    12  var line = 'api failed=$failedChecks status=$status';13  print(line);14}
    outputapi failed=0 status=ready
    values this stepapi failed=0 status=readyline
status function `classify` isolates the ready/blocked decision from the reporting string.
threshold `maxAllowed` makes the policy visible instead of hiding it in a magic label.
report line The final string combines the service signal and the derived status.