toString method Null safety

  1. @override
String toString(
  1. {int depth = 0}
)
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({int depth = 0}) {
  final buf = StringBuffer();
  for (var i = 0; i < depth; i++) {
    buf.write("\t");
  }

  if (patternMatcher != null) {
    buf.write("(match: ${patternMatcher!.pattern})");
  }

  buf.writeln(
    "Controller: ${specification?.controller?.nextController?.runtimeType}",
  );
  equalityChildren.forEach((seg, spec) {
    for (var i = 0; i < depth; i++) {
      buf.write("\t");
    }

    buf.writeln("/$seg");
    buf.writeln(spec.toString(depth: depth + 1));
  });

  return buf.toString();
}