Reputation: 393
I have looked at the following links before writing this question:
The code:
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]);
I simply don't know why the error exists so please help me out. Thank You!
EDIT: I can change the data to a limit if that helps solve the problem
Upvotes: 1
Views: 7565
Reputation: 908
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);
Upvotes: 1
Reputation: 31
You should declare the type like this:
Map<String, dynamic> indexedData = Map<String, dynamic>.from(data[index]);
Upvotes: 1