Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter web: Convert CSV to list for

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

Working CSV file conversion,

Not working csv file conversion, the structure isn't the same, it's a big chunck

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

like image 920
Judas B Avatar asked Aug 31 '25 01:08

Judas B


1 Answers

You should add eol: "\r\n",fieldDelimiter: "," to CsvToListConverter(). your code will be like this:

employeeData = CsvToListConverter(eol: "\r\n",fieldDelimiter: ",").convert(bytes);
like image 186
Muaiyed Al-qateefi Avatar answered Sep 03 '25 00:09

Muaiyed Al-qateefi