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() {
  final buf = StringBuffer();

  void logField(String name, FieldStat stat) {
    final ok = stat.consensus != null && stat.consensus.toString().isNotEmpty;
    final emoji = ok ? '✅' : '❌';
    buf.write('$name: ${stat.consensus ?? "-"}  ($emoji ${stat.consensusCount}) \t');
  }

  logField("CountryCode", countryCodeStat);
  logField("IssuingState", issuingStateStat);
  logField("DocumentNumber", documentNumberStat);
  logField("LastName", lastNameStat);
  logField("FirstName", firstNameStat);
  logField("Nationality", nationalityStat);
  logField("BirthDate", birthDateStat);
  logField("ExpiryDate", expiryDateStat);
  logField("Sex", sexStat);
  logField("PersonalNumber", personalNumberStat);
  logField("OptionalData", optionalDataStat);
  logField("Line1", line1Stat);
  logField("Line2", line2Stat);
  logField("Line3", line3Stat);
  logField("docType", docTypeStat);

  return buf.toString();
}