toString method
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 precision = 6}) {
var header = '${shape.item1}x${shape.item2} matrix';
var maxPrecision = [
for (var line in values)
for (var entry in line) entry.toStringAsFixed(precision).length
].fold(precision, max);
var minPadding = 4;
var indent = ' ';
var content = '';
for (var line in values) {
content += '$indent';
for (var value in line) {
var negPrev = value < 0 ? '-' : ' ';
var spaceCount = maxPrecision +
minPadding -
value.abs().toStringAsFixed(precision).length;
var spaces = [for (var _ in range(end: spaceCount)) ' '].join();
content += negPrev;
content += value.abs().toStringAsFixed(precision);
content += spaces;
}
content += '\n';
}
return '$header\n$content';
}