columnValues<T> method

List<T?> columnValues<T>(
  1. String column, {
  2. bool ignoreCase = false,
  3. bool includeNulls = true,
})

Returns all values for column as a typed list.

Values that are not assignable to T are skipped. When includeNulls is true, null entries are preserved as null in the result.

Implementation

List<T?> columnValues<T>(
  String column, {
  bool ignoreCase = false,
  bool includeNulls = true,
}) {
  final idx = columnIndex(column, ignoreCase: ignoreCase);
  if (idx == null) {
    return const [];
  }
  final out = <T?>[];
  for (final row in rows) {
    if (idx >= row.length) {
      if (includeNulls) {
        out.add(null);
      }
      continue;
    }
    final value = row[idx];
    if (value == null) {
      if (includeNulls) {
        out.add(null);
      }
      continue;
    }
    if (value is T) {
      out.add(value);
    }
  }
  return out;
}