why I got Unhandled Exception: type 'List<List<String>>' is not a subtype of type 'List<String>' of 'value' With Flutter?

41 views Asked by At

I'm trying to get data from a list and then put all the values in a second list. Unfortunately, I go an error: type 'List<List>' is not a subtype of type 'List' of 'value' this is the code :

  List? getData() {
    setup.generateCsv((event) async {
      List<List<String>> data = [
        ["X", " Y", "Z", "Z"],
        [mevent.data[0], event.data[1], event.data[2]],
      ];
      List data2 = data;
      data2.add(data);
      print("DATA DATA , $data2");
      return data2;
1

There are 1 answers

9
Md. Yeasin Sheikh On

You can add list like

  List<List<String>> data = [...];
  List<String> data2 = [];
  for (final e in data) {
    data2.addAll(e);
  }
  return data2;