toString method

  1. @override
String toString()
override

A string representation of this object.

Some classes have a default textual representation, often paired with a static parse function (like int.parse). These classes will provide the textual representation as their string representation.

Other classes have no meaningful textual representation that a program will care about. Such classes will typically override toString to provide useful information when inspecting the object, mainly for debugging or logging.

Implementation

@override
String toString() {
  var text = super.toString();
  if (printEvaluations.isNotEmpty) {
    text += "\nPrint evaluation (line-by-line):";
  }
  for (final (index, printEvaluation) in printEvaluations.indexed) {
    final similarityPercentage = printEvaluation.$4 != null
        ? (printEvaluation.$4! * 100).round()
        : null;
    switch (printEvaluation.$3) {
      case DartBlockPrintEvaluationType.correct:
        text +=
            "\n[Line #${index + 1} - Correct] Expected '${printEvaluation.$1}'${similarityPercentage != null && similarityPercentage < 1 ? " → $similarityPercentage% match (Your output: ${printEvaluation.$2})" : ""}";
        break;
      case DartBlockPrintEvaluationType.wrong:
        text +=
            "\n[Line #${index + 1} - Wrong] Expected '${printEvaluation.$1}'${similarityPercentage != null && similarityPercentage < 1 ? " → Got '${printEvaluation.$2}" : ""}'";
        break;
      case DartBlockPrintEvaluationType.missing:
        text +=
            "\n[Line #${index + 1} - Missing] Expected '${printEvaluation.$1}'";
        break;
    }
  }

  return text;
}