flushRows method

void flushRows()

Implementation

void flushRows() {
    if (_rows.isNotEmpty) {

      var maxWidth = <int>[];

      _rows.forEach((columns) {
          var numColumns = columns.length;
          for (var i=0; i < numColumns; i++) {
            var currentColumnStringValue = columns[i];
            var currentColumnStringValueLength = currentColumnStringValue == null ? 0 : currentColumnStringValue.length;
            if (maxWidth.length < i + 1) {
                maxWidth.add(currentColumnStringValueLength);
            } else {
                if (maxWidth[i] < currentColumnStringValueLength) {
                  maxWidth.insert(i, currentColumnStringValueLength);
                }
            }
          }
      });

      var rowSB = StringBuffer();

      _rows.forEach((columns) {
          var numColumns = columns.length;
          for (var i=0; i < numColumns; i++) {
            var currentColumnStringValue = columns[i];
            var currentItemWidth = currentColumnStringValue == null ? 0 : currentColumnStringValue.length;
            var maxWidth1 = maxWidth[i];
            rowSB.write(currentColumnStringValue ?? '');

            if (currentItemWidth < maxWidth1) {
                for (var j=currentItemWidth; j < maxWidth1; j++) {
                  rowSB.write(' '); // right pad
                }
            }
          }
          _content.add(IndentedLine(rowSB.toString(), _indents));
          rowSB.clear();
      });

      _rows.clear();
    }
}