lastRow method
Fetches last row, maps it to other row and returns map.
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
mapTo - optional (defaults to 1), index of a row to map cells to
(keys of returned map),
rows start at index 1
inRange - optional (defaults to false), whether should be fetched last
row in range (respects fromColumn and length) or last row in table
Returns row as Future Map of String to Cell.
Returns Future null if there are less than 2 rows.
Throws GSheetsException.
Implementation
Future<Map<String, Cell>?> lastRow({
int fromColumn = 1,
int mapTo = 1,
int length = -1,
bool inRange = false,
}) async {
checkIndex('mapTo', mapTo);
if (inRange) {
final rows = await _cells._ws.values.allRows(
fromColumn: fromColumn,
length: length,
);
final row = rows.length;
if (row < 2) return null;
checkMapTo(row, mapTo);
final keys = get(rows, at: mapTo - 1, or: <String>[])!;
final values = rows[row - 1];
return _wrapRow(keys, values, row, fromColumn);
} else {
checkIndex('fromColumn', fromColumn);
final rows = await _cells._ws.values.allRows();
final row = rows.length;
if (row < 2) return null;
checkMapTo(row, mapTo);
final keys = extractSublist(
get(rows, at: mapTo - 1, or: <String>[])!,
from: fromColumn - 1,
length: length,
);
final values = extractSublist(
rows[row - 1],
from: fromColumn - 1,
length: length,
);
return _wrapRow(keys, values, row, fromColumn);
}
}