Getting error -
error: Undefined name 'csvCodec'. (undefined_identifier at [easy_csv] example\exa.dart:10)

I implemented decoder example from dart csv package like -

import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:csv/csv.dart';

main() async {
  final input = new File('foo.csv').openRead();
  final fields =
      await input.transform(utf8.decoder).transform(csvCodec.decoder).toList();
}

1 Answers

0
Sacchidanand Gogawale On Best Solutions

Issue is now solved.

As with Dart 2, csv was no longer able to be a codec & corresponding documentation was not removed. This change is now reflected in documentation


Example code for reading csv file & printing them on according latest version 4.0.3

import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:csv/csv.dart';

main() async { 
  //TODO Change file_name
  String file_name = 'foo.csv';
  final input = File(file_name).openRead();
  //Every csv row is converted to a list of values. 
  //Unquoted strings looking like numbers (integers and doubles) are by default converted to ints or doubles.
  final fields = await input.transform(utf8.decoder).transform(new CsvToListConverter()).toList();
  print(fields);
}