allRows method
Fetches all rows, maps them to specific row and returns as list of maps.
Expands current sheet's size if requested range is out of sheet's bounds.
fromRow
- optional (defaults to 1), index of a first returned row
(rows before fromRow
will be skipped),
rows start at index 1
count
- optional (defaults to -1), the number of requested rows
if count is -1
, all rows starting from fromRow
will be returned
fromColumn
- optional (defaults to 1), index of a column that requested
rows start from (values before fromColumn
will be skipped),
columns start at index 1 (column A)
length
- optional (defaults to -1), the length of requested rows
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 maps),
rows start at index 1
Returns rows as Future List<Map<String, String>>
.
Returns Future null
if there are less than 2 rows.
Throws GSheetsException.
Implementation
Future<List<Map<String, String>>?> allRows({
int fromRow = 1,
int fromColumn = 1,
int length = -1,
int count = -1,
int mapTo = 1,
}) async {
checkIndex('fromRow', fromRow);
checkIndex('mapTo', mapTo);
final rows = await _values.allRows(
fromColumn: fromColumn,
length: length,
);
if (rows.length < 2) return null;
final maps = <Map<String, String>>[];
final keys = get(rows, at: mapTo - 1, or: <String>[])!;
if (keys.isEmpty) return maps;
final start = min(fromRow - 1, rows.length);
final end = count < 1 ? rows.length : min(start + count, rows.length);
for (var i = start; i < end; i++) {
if (i != mapTo - 1) {
maps.add(_wrap(keys, rows[i]));
}
}
return maps;
}