Answers for "export flutter data to csv"

1

export flutter data to csv

import 'dart:html';

import 'package:csv/csv.dart';

class ExportCsv {
  final List data;
  ExportCsv({this.data});

  List<List<dynamic>> rows = List<List<dynamic>>();
  downloadData() {
    for (int i = 0; i < data.length; i++) {

      List<dynamic> 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();
  }
}
Posted by: Guest on April-23-2021

Code answers related to "export flutter data to csv"

Browse Popular Code Answers by Language