columns property

int columns

The number of vertical alignment lines in this table.

Changing the number of columns will remove any children that no longer fit in the table.

Changing the number of columns is an expensive operation because the table needs to rearrange its internal representation.

Implementation

int get columns => _columns;
void columns=(int value)

Implementation

set columns(int value) {
  assert(value >= 0);
  if (value == columns) {
    return;
  }
  final int oldColumns = columns;
  final List<RenderBox?> oldChildren = _children;
  _columns = value;
  _children = List<RenderBox?>.filled(columns * rows, null);
  final int columnsToCopy = math.min(columns, oldColumns);
  for (int y = 0; y < rows; y += 1) {
    for (int x = 0; x < columnsToCopy; x += 1) {
      _children[x + y * columns] = oldChildren[x + y * oldColumns];
    }
  }
  if (oldColumns > columns) {
    for (int y = 0; y < rows; y += 1) {
      for (int x = columns; x < oldColumns; x += 1) {
        final int xy = x + y * oldColumns;
        if (oldChildren[xy] != null) {
          dropChild(oldChildren[xy]!);
        }
      }
    }
  }
  markNeedsLayout();
}