lastRow method

Future<List<Cell>?> lastRow({
  1. int fromColumn = 1,
  2. int length = -1,
  3. bool inRange = false,
})

Fetches last row.

Expands current sheet's size if requested range is out of sheet's bounds.

fromColumn - optional (defaults to 1), index of a column that requested row starts from (cells before fromColumn will be skipped), columns start at index 1 (column A)

length - optional (defaults to -1), the length of a requested row if length is -1, all cells starting from fromColumn will be returned

inRange - optional (defaults to false), whether should be fetched last row in range (respects fromColumn and length) or last row in table

Returns last row as Future List of Cell. Returns Future null if there are no rows.

Throws GSheetsException.

Implementation

Future<List<Cell>?> lastRow({
  int fromColumn = 1,
  int length = -1,
  bool inRange = false,
}) async {
  if (inRange) {
    final rows = await _ws.values.allRows(
      fromColumn: fromColumn,
      length: length,
    );
    if (rows.isEmpty) return null;
    return _wrapRow(rows.last, rows.length, fromColumn);
  } else {
    checkIndex('fromColumn', fromColumn);
    final rows = await _ws.values.allRows();
    if (rows.isEmpty) return null;
    final list = extractSublist(
      rows.last,
      from: fromColumn - 1,
      length: length,
    );
    return _wrapRow(list, rows.length, fromColumn);
  }
}