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() {
  // Note that the order of bytes in the returned string is different from the
  // internal byte representation of a GUID value. The order of the beginning
  // four-byte group and the next two two-byte groups are reversed; the order
  // of the final two-byte group and the closing six-byte group are the same.
  //
  // The following zero-indexed list provides the offset for each 8-bit hex
  // value within the 16-byte array.
  const offsets = [3, 2, 1, 0, 5, 4, 7, 6, 8, 9, 10, 11, 12, 13, 14, 15];

  final guidAsHexValues =
      offsets.map((idx) => bytes[idx].toRadixString(16).padLeft(2, '0'));

  final formattedString = guidAsHexValues.join('');
  final part1 = formattedString.substring(0, 8);
  final part2 = formattedString.substring(8, 12);
  final part3 = formattedString.substring(12, 16);
  final part4 = formattedString.substring(16, 20);
  final part5 = formattedString.substring(20);

  return '{$part1-$part2-$part3-$part4-$part5}';
}