There is plenty example of CSV to list for flutter apps, I'm facing issues with flutter web and the conversion of the file.
Some CSV aren't working as desired, I guess that it's a formatting issue Here is the converting function when a user upload a file
Future _openFileExplorer() async {
FilePickerResult? result = await FilePicker.platform.pickFiles(
allowMultiple: false,
withData: true,
type: FileType.custom,
allowedExtensions: ['csv']);
if (result != null) {
//decode bytes back to utf8
final bytes = utf8.decode((result.files.first.bytes)!.toList());
setState(() {
//from the csv plugin
employeeData = CsvToListConverter().convert(bytes);
});
}
}
Working CSV file conversion
,
Not working csv file conversion, the structure isn't the same, it's a big chunck
,
I did a complete repo of the project if you want to try, added some photos in the README,
https://github.com/valentincx/csv_to_list_for_web
You should add eol: "\r\n",fieldDelimiter: ","
to CsvToListConverter()
. your code will be like this:
employeeData = CsvToListConverter(eol: "\r\n",fieldDelimiter: ",").convert(bytes);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With