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 StringBuffer buffer = StringBuffer("{");
  final Uint8List? header = isoHeader;
  if (header != null) buffer.write("\"header\":\"${IsoUtil.hexString(header)}\",");
  if (isReject) buffer.write("\"rejectCode\":\"$rejectCode\",");
  buffer.write("\"fields\":[");
  int index = 0;
  fields.forEach((int field, IsoComponent<Object> component) {
    if (index > 0) buffer.write(",");
    buffer.write("{\"id\":\"$field\",\"type\":\"${component.type}\",\"value\":\"$component\"}");
    index++;
  });
  buffer.write("]}");
  return buffer.toString();
}