export flutter data to csv code example
Example: export flutter data to csv
import 'dart:html';
import 'package:csv/csv.dart';
class ExportCsv {
final List data;
ExportCsv({this.data});
List> rows = List>();
downloadData() {
for (int i = 0; i < data.length; i++) {
List row = List();
row.add(data[i].userName);
row.add(data[i].userLastName);
row.add(data[i].userEmail);
rows.add(row);
}
String csv = const ListToCsvConverter().convert(rows);
new AnchorElement(href: "data:text/plain;charset=utf-8,$csv")
..setAttribute("download", "data.csv")
..click();
}
}