CsvTable class
2D CSV data structure with headers and data rows.
Query, sort, transform, and aggregate operations are available
via extensions from the query/ and transform/ layers.
Mutation rule
Methods that return a CsvTable (where, range, take, skip,
distinct, map, sortedBy, copy) return a new table and leave
this one untouched. Methods that return void (sortBy, addRow,
addColumn, removeColumn, and the other structural operations)
mutate this table in place.
- Available extensions
Constructors
-
CsvTable(List<
List> rows) - Create from raw 2D data (no headers).
-
CsvTable.empty({List<
String> headers = const []}) - Create empty table with column definitions.
-
CsvTable.fromData({required List<
String> headers, required List<List> rows}) - Create from explicit headers + data rows.
-
CsvTable.fromMaps(List<
Map< maps)String, dynamic> > -
Create from a list of Maps.
factory
-
CsvTable.internal(List<
String> _headers, List<List> _data) - Internal constructor for extensions. Creates without copying data: the caller must hand over freshly allocated lists it no longer uses.
- CsvTable.parse(String csv, {CsvConfig config = const CsvConfig()})
-
Parse from CSV string.
factory
-
CsvTable.withHeaders(List<
List> rows) - Create from 2D data where first row is headers.
Properties
- columnCount → int
-
Number of columns.
no setter
- first → CsvRow
-
Get first row.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasHeaders → bool
-
Whether headers are defined.
no setter
-
headers
→ List<
String> -
Column headers. Empty list if no headers defined.
no setter
- isEmpty → bool
-
Whether the table has no data rows.
no setter
- isNotEmpty → bool
-
no setter
-
iterator
→ Iterator<
CsvRow> -
Iterate over rows as CsvRow.
no setter
- last → CsvRow
-
Get last row.
no setter
-
mutableHeaders
→ List<
String> -
Direct access to the mutable headers list, without copying.
no setter
-
rawData
→ List<
List> -
Direct access to the underlying data rows, without copying.
no setter
- rowCount → int
-
Number of data rows.
no setter
-
rows
→ List<
CsvRow> -
Get all rows as CsvRow list.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
addColumn(
String name, {dynamic defaultValue}) → void -
Available on CsvTable, provided by the CsvTableManipulation extension
Add a new column with optional default value. -
addRow(
List row) → void - Add a row at the end.
-
addRowFromMap(
Map< String, dynamic> map) → void - Add a row from a map (requires headers).
-
addRows(
List< List> rows) → void - Add multiple rows.
-
any(
bool test(CsvRow row)) → bool -
Available on CsvTable, provided by the CsvTableFiltering extension
Check if any row matches predicate. -
avg(
String column) → double -
Available on CsvTable, provided by the CsvTableAggregation extension
Average of numeric values in a column. -
buildHeaderMap(
) → Map< String, int> ? - Build header name-to-index map, or null if no headers.
-
cell(
int row, int col) → dynamic - Get cell value at (row, col).
-
cellByName(
int row, String columnName) → dynamic - Get cell value by row index and column name.
-
column(
String name) → List - Get all values in a column by header name.
-
columnAt(
int index) → List - Get all values in a column by index.
-
conformsTo(
CsvSchema schema) → bool - Check if table conforms to schema.
-
copy(
) → CsvTable - Deep copy of the table.
-
count(
String column) → int -
Available on CsvTable, provided by the CsvTableAggregation extension
Count of non-null values in a column. -
distinct(
{List< String> ? columns}) → CsvTable -
Available on CsvTable, provided by the CsvTableFiltering extension
Get distinct rows based on all fields or specific columns. -
every(
bool test(CsvRow row)) → bool -
Available on CsvTable, provided by the CsvTableFiltering extension
Check if all rows match predicate. -
firstWhere(
bool test(CsvRow row)) → CsvRow? -
Available on CsvTable, provided by the CsvTableFiltering extension
Find first row matching predicate (or null). -
fold<
T> (T initial, T combine(T accumulator, CsvRow row)) → T -
Available on CsvTable, provided by the CsvTableManipulation extension
Reduce rows to a single value. -
getColumn(
String name) → CsvColumn - Get column descriptor by name.
-
getColumnAt(
int index) → CsvColumn - Get column descriptor by index.
-
groupBy(
String column) → Map< dynamic, CsvTable> -
Available on CsvTable, provided by the CsvTableAggregation extension
Group rows by a column's value. ReturnsMap<value, CsvTable>. -
inferSchema(
) → CsvSchema - Infer a CsvSchema from the table's headers and data.
-
insertColumn(
int index, String name, {dynamic defaultValue}) → void -
Available on CsvTable, provided by the CsvTableManipulation extension
Insert column at index. -
insertRow(
int index, List row) → void - Insert a row at index.
-
map(
CsvRow transform(CsvRow row)) → CsvTable -
Available on CsvTable, provided by the CsvTableManipulation extension
Apply a transform to every row. Returns a new CsvTable; this table is left untouched. -
max(
String column) → dynamic -
Available on CsvTable, provided by the CsvTableAggregation extension
Maximum value in a column. -
min(
String column) → dynamic -
Available on CsvTable, provided by the CsvTableAggregation extension
Minimum value in a column. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
range(
int start, [int? end]) → CsvTable -
Available on CsvTable, provided by the CsvTableFiltering extension
Get rows in index range. Returns new CsvTable. -
removeColumn(
String name) → List -
Available on CsvTable, provided by the CsvTableManipulation extension
Remove column by name. Returns removed values. -
removeColumnAt(
int index) → List -
Available on CsvTable, provided by the CsvTableManipulation extension
Remove column by index. Returns removed values. -
removeRow(
int index) → CsvRow - Remove row at index. Returns removed row.
-
removeWhere(
bool test(CsvRow row)) → int - Remove rows matching predicate. Returns count removed.
-
renameColumn(
String oldName, String newName) → void -
Available on CsvTable, provided by the CsvTableManipulation extension
Rename a column. -
reorderColumns(
List< String> newOrder) → void -
Available on CsvTable, provided by the CsvTableManipulation extension
Reorder columns to match the given header order. -
setCell(
int row, int col, dynamic value) → void - Set cell value.
-
setCellByName(
int row, String columnName, dynamic value) → void - Set cell by row index and column name.
-
setHeaders(
List< String> h) → void - Replace headers list. The new list is not validated against the current column count.
-
skip(
int count) → CsvTable -
Available on CsvTable, provided by the CsvTableFiltering extension
Skip first N rows. -
sort(
int compare(CsvRow a, CsvRow b)) → void -
Available on CsvTable, provided by the CsvTableSorting extension
Sort with custom comparator (stable, in place). -
sortBy(
String column, {bool ascending = true}) → void -
Available on CsvTable, provided by the CsvTableSorting extension
Sort by column name (stable, in place). -
sortByIndex(
int column, {bool ascending = true}) → void -
Available on CsvTable, provided by the CsvTableSorting extension
Sort by column index (stable, in place). -
sortByMultiple(
List< (String, bool)> criteria) → void -
Available on CsvTable, provided by the CsvTableSorting extension
Sort by multiple columns (stable, in place). -
sortedBy(
String column, {bool ascending = true}) → CsvTable -
Available on CsvTable, provided by the CsvTableSorting extension
Return a copy of this table sorted by column name; this table is left untouched. -
sum(
String column) → num -
Available on CsvTable, provided by the CsvTableAggregation extension
Sum of numeric values in a column. -
take(
int count) → CsvTable -
Available on CsvTable, provided by the CsvTableFiltering extension
Get first N rows. -
toCsv(
{CsvConfig config = const CsvConfig()}) → String - Encode to CSV string.
-
toFormattedString(
{int maxRows = 20, int maxColumnWidth = 30}) → String - Pretty-print as aligned table.
-
toList(
{bool includeHeaders = false}) → List< List> - Convert to list of rows, optionally including header row.
-
toMaps(
) → List< Map< String, dynamic> > - Convert to list of maps.
-
toString(
) → String -
A string representation of this object.
override
-
transformColumn(
String name, dynamic transform(dynamic value)) → void -
Available on CsvTable, provided by the CsvTableManipulation extension
Apply a transform to every cell in a column. -
validate(
CsvSchema schema) → List< CsvValidationException> - Validate all rows against a schema. Returns list of violations.
-
where(
bool test(CsvRow row)) → CsvTable -
Available on CsvTable, provided by the CsvTableFiltering extension
Filter rows matching predicate. Returns new CsvTable.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
-
operator [](
int index) → CsvRow - Get row by index as CsvRow.
-
operator []=(
int index, List row) → void - Set/replace row at index.
Static Methods
-
compareValues(
dynamic a, dynamic b, bool ascending) → int - Compare two dynamic values with a documented total order.