insertRow method

void insertRow(
  1. List<Object> row, {
  2. int? index,
})

Adds a new row to the table.

Implementation

void insertRow(List<Object> row, {int? index}) {
  // If this is the first row to be added to the table, and there are no
  // column definitions added so far, then treat this as a headerless table,
  // adding an empty header row and setting defaults for the table structure.
  if (_table[0].isEmpty) {
    _table[0] = List<String>.filled(row.length, '', growable: true);
    _columnAlignments.clear();
    _columnAlignments.insertAll(
        0, List<TextAlignment>.filled(columns, TextAlignment.left));
    _columnWidths.clear();
    _columnWidths.insertAll(0, List<int>.filled(columns, 0));
    showHeader = false;
  }

  // Take as many elements as there are columns, padding as necessary. Extra
  // elements are discarded. This enables a sparse row to be added while
  // ensuring that the table remains non-ragged.
  final fullRow = [...row, for (var i = row.length; i < columns; i++) ''];
  _table.insert(index ?? rows + 1, fullRow.take(columns).toList());

  assert(_tableIntegrity);
}