当前位置: 首页 > 知识库问答 >
问题:

类型_InternalLinkedHashMap不是函数结果类型列表的子类型

杜俊楚
2023-03-14

在写这个问题之前,我看了以下链接:

  • 未处理的异常:InternalLinkedHashMap

守则:

List data = [
    {
      "title" : "Particulate matter",
      "desc" : "The term used to describe a mixture of solid particles and liquid droplets found in the air",
      "amt" : 500,
      "diseases" : "Particulate matter is responsible for asthma in many people. Also, a topic dermatitis, allergic rhinitisare diseases that can be caused by this",
      "precaution" : "Switching to cleaner appliances and reducing the amount of smoking will surely ensure less exposureof particulate matter in the environment",
      "image" : 'https://images.pexels.com/photos/3668372/pexels-photo-3668372.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260',
      "color" : Color(0xFF6E7E5D).withOpacity(.3)
    },
// loads of data in this structure
];

// the line of error
Map indexedData = Map<String, dynamic>.from(data[index]);

我只是不知道为什么错误存在,所以请帮帮我。谢谢你!

编辑:如果有助于解决问题,我可以将数据更改为限制

共有2个答案

韩捷
2023-03-14

您应该这样声明类型:

Map<String, dynamic> indexedData = Map<String, dynamic>.from(data[index]);
戚晨
2023-03-14
List data = [
    {
      "title": "Particulate matter",
      "desc":
          "The term used to describe a mixture of solid particles and liquid droplets found in the air",
      "amt": 500,
      "diseases":
          "Particulate matter is responsible for asthma in many people. Also, a topic dermatitis, allergic rhinitisare diseases that can be caused by this",
      "precaution":
          "Switching to cleaner appliances and reducing the amount of smoking will surely ensure less exposureof particulate matter in the environment",
      "image":
          'https://images.pexels.com/photos/3668372/pexels-photo-3668372.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260',
      "color": Color(0xFF6E7E5D).withOpacity(.3),
    },
  ];

  Map<String, dynamic> indexedData = {};

  data.forEach((mapElement) {
    Map map = mapElement as Map;
    map.forEach((key, value) {
      indexedData[key] = value;
    });
  });

print(indexedData);
 类似资料: