【问题标题】:why I got Unhandled Exception: type 'List<List<String>>' is not a subtype of type 'List<String>' of 'value' With Flutter?为什么我得到 Unhandled Exception: type \'List<List<String>>\' is not a subtype of type \'List<String>\' of \'value\' With Flutter?
【发布时间】:2023-01-12 04:36:30
【问题描述】:

我试图从列表中获取数据,然后将所有值放在第二个列表中。 不幸的是,我出错了:type 'List<List>' is not a subtype of type 'List' of 'value' 这是代码:

  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;

【问题讨论】:

    标签: flutter list dart add collect


    【解决方案1】:

    您可以添加列表,如

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

    【讨论】:

      猜你喜欢
      • 2022-11-20
      • 1970-01-01
      • 2020-04-12
      • 2023-02-17
      • 2021-10-22
      • 1970-01-01
      • 2022-11-19
      • 1970-01-01
      • 2021-09-08
      相关资源
      最近更新 更多