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 (values 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 values starting from fromColumn will be returned
mapTo - optional (defaults to 1), index of a row to map values 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 String.
Returns Future null if there are less than 2 rows.
Throws GSheetsException.
Implementation
Future<Map<String, String>?> lastRow({
int fromColumn = 1,
int length = -1,
int mapTo = 1,
bool inRange = false,
}) async {
checkIndex('mapTo', mapTo);
if (inRange) {
final rows = await _values.allRows(
fromColumn: fromColumn,
length: length,
);
if (rows.length < 2) return null;
checkMapTo(rows.length, mapTo);
final row = rows.length;
final keys = get(rows, at: mapTo - 1, or: <String>[])!;
final values = get(rows, at: row - 1, or: <String>[])!;
return _wrap(keys, values);
} else {
checkIndex('fromColumn', fromColumn);
final rows = await _values.allRows();
if (rows.length < 2) return null;
checkMapTo(rows.length, mapTo);
final row = rows.length;
final keys = extractSublist(
get(rows, at: mapTo - 1, or: <String>[])!,
from: fromColumn - 1,
length: length,
);
final values = extractSublist(
get(rows, at: row - 1, or: <String>[])!,
from: fromColumn - 1,
length: length,
);
return _wrap(keys, values);
}
}