csv_plus v1.2.0
pub.dev GitHub

Headers and named columns

Address fields by name, so inserting a column does not silently break your code.

Install#

dart pub add csv_plus
import 'package:csv_plus/csv_plus.dart';

Decode with headers#

final codec = CsvCodec();
final csv = 'name,age\nAlice,30\nBob,25';

final people = codec.decodeWithHeaders(csv);

print(people.first['name']); // Alice
print(people.first['age']);  // 30  (an int, not "30")

Index-based access breaks the moment someone adds a column to the export. Name-based access does not.

As a table#

CsvTable gives the same named access plus querying:

final table = CsvTable.parse('name,age,city\nAlice,30,NYC\nBob,25,LA');

table.rows.first['city']; // NYC
print(table.toFormattedString()); // aligned, readable output

When the file has no header#

final codec = CsvCodec(CsvConfig(hasHeader: false));

When the header is not the first line#

Drop the rows above it before the header is read:

final codec = CsvCodec(CsvConfig(skipRows: 2, hasHeader: true));