close2 / csv

A dart csv to list codec / converter
MIT License
98 stars 24 forks source link

[Feature request] Support for parsing the header #72

Open orkun1675 opened 4 months ago

orkun1675 commented 4 months ago

The current API of accesing fields values is:

List<List<dynamic>> rows = const CsvToListConverter(
      eol: '\n',
      shouldParseNumbers: false,
    ).convert(fileContents);

// Row zero has the headers; discard it.
String idColumnValue = rows[1][0];

Which works if the file columns are guranteed to be in a static order.

It would be great if we could access columns values by their name:

List<List<dynamic>> rows = const CsvToListConverter(
      eol: '\n',
      shouldParseNumbers: false,
      parseHeaders: true, // New config option
    ).convert(fileContents);

// Row zero had headers but was parsed and dropped.
String idColumnValue = rows[0]["id"];