close2 / csv

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

Not working on iOS #31

Closed tantzygames closed 1 year ago

tantzygames commented 5 years ago

using csv: ^4.0.3

I have successfully converted a csv file on Andoid, but the same code doesn't work on iOS.

String codetxt = await rootBundle.loadString('assets/file.csv');
List<List<dynamic>> codeList = CsvToListConverter().convert(codetxt);
print('codelist size ' + codeList.length.toString());

This results in 66k entries for Android, but only 1 for iOS.

I've checked that the csv is loading properly on iOS. I'm not sure what else I should be looking for to track down the cause?

close2 commented 5 years ago

Are you trying to parse the same csv file?

My first guess would be that the End Of Line character is different.

Try the FirstOccurenceSettingsDetector:

var d = new FirstOccurrenceSettingsDetector(eols: ['\r\n', '\n']);

String codetxt = await rootBundle.loadString('assets/file.csv');
List<List<dynamic>> codeList = CsvToListConverter(csvSettingsDetector: d).convert(codetxt);
print('codelist size ' + codeList.length.toString());
tantzygames commented 5 years ago

Yes, it's the same file, but your suggestion worked. Thanks!

I'm compiling Android on Windows and iOS on Mac. The file has \r\n line endings, but maybe mac is ignoring the \r which was causing the problem?

PS Thanks so much for this package. CSV is 600k, equivalent json is over 2Mb and slow to load on iOS.

bettdouglas commented 5 years ago

This problem started after upgrading flutter. One has to specify this way explicitly. On my side, it worked well before the update, but after going to flutter 1.9.1 from flutter 1.7.8, i had to explicitly specify var d = new FirstOccurrenceSettingsDetector(eols: ['\r\n', '\n']);

Are you trying to parse the same csv file?

My first guess would be that the End Of Line character is different.

Try the FirstOccurenceSettingsDetector:

var d = new FirstOccurrenceSettingsDetector(eols: ['\r\n', '\n']);

String codetxt = await rootBundle.loadString('assets/file.csv');
List<List<dynamic>> codeList = CsvToListConverter(csvSettingsDetector: d).convert(codetxt);
print('codelist size ' + codeList.length.toString());
joknjokn commented 5 years ago

I had to import a specific file from the csv-library in order to access FirstOccurenceSettingsDetector:

import 'package:csv/csv_settings_autodetection.dart' as csvAuto;

var d = new csvAuto.FirstOccurrenceSettingsDetector(eols: ['\r\n', '\n']);
Automatik commented 4 years ago

Are you trying to parse the same csv file?

My first guess would be that the End Of Line character is different.

Try the FirstOccurenceSettingsDetector:

var d = new FirstOccurrenceSettingsDetector(eols: ['\r\n', '\n']);

String codetxt = await rootBundle.loadString('assets/file.csv');
List<List<dynamic>> codeList = CsvToListConverter(csvSettingsDetector: d).convert(codetxt);
print('codelist size ' + codeList.length.toString());

Thank you, it worked for me too. Flutter version 1.20.1 and csv: ^4.0.3

nathantaal commented 1 year ago

I ran the code on my Windows PC giving my Android virtual and real device a working file, but when deployed via Play Store it didn't work. This finally made me realize it's just a compiletime issue. My app is built on a Linux device. This issue should be closed, as it is not really an issue :)

close2 commented 1 year ago

Thanks for the feedback!