allColumns method

Future<List<Map<String, String>>?> allColumns({
  1. int fromColumn = 1,
  2. int fromRow = 1,
  3. int length = -1,
  4. int count = -1,
  5. int mapTo = 1,
})

Fetches all columns, maps them to specific column and returns as list of maps.

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

fromColumn - optional (defaults to 1), index of a first returned column (columns before fromColumn will be skipped), columns start at index 1 (column A)

count - optional (defaults to -1), the number of requested columns if count is -1, all columns starting from fromColumn will be returned

fromRow - optional (defaults to 1), index of a row that requested columns start from (values before fromRow will be skipped), rows start at index 1

length - optional (defaults to -1), the length of requested columns if length is -1, all values starting from fromRow will be returned

mapTo - optional (defaults to 1), index of a column to map values to (keys of returned maps), columns start at index 1 (column A)

Returns columns as Future List<Map<String, String>>. Returns Future null if there are less than 2 columns.

Throws GSheetsException.

Implementation

Future<List<Map<String, String>>?> allColumns({
  int fromColumn = 1,
  int fromRow = 1,
  int length = -1,
  int count = -1,
  int mapTo = 1,
}) async {
  checkIndex('fromColumn', fromColumn);
  checkIndex('mapTo', mapTo);
  final columns = await _values.allColumns(
    fromRow: fromRow,
    length: length,
  );
  if (columns.length < 2) return null;
  final maps = <Map<String, String>>[];
  final keys = get(columns, at: mapTo - 1, or: <String>[])!;
  if (keys.isEmpty) return maps;
  final start = min(fromColumn - 1, columns.length);
  final end = count < 1 ? columns.length : min(start + count, columns.length);
  for (var i = start; i < end; i++) {
    if (i != mapTo - 1) {
      maps.add(_wrap(keys, columns[i]));
    }
  }
  return maps;
}