Unhandled Exception: InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'List<dynamic>
Here are 2 common ways this could go wrong:
If your response is a json object like
[ { key1: value1, key2: value2, key3: value3, }, { key1: value1, key2: value2, key3: value3, }, ..... ]
Then, we use
data[0]["name"]
, notdata[0].name
Unless we cast to an object that has the name property, we cannot usedata[0].name
We cast like this
data = json.decode(response.body).cast<ObjectName>();
ObjectName
can be whatever object you want (Inbuilt or Custom). But make sure it has the name propertyIf your response is a JSON object like
{ dataKey: [ { key1: value1, key2: value2, key3: value3, } ] }
Then
json.decode
will return a Map, not a ListMap<String, dynamic> map = json.decode(response.body); List<dynamic> data = map["dataKey"]; print(data[0]["name"]);
You can use
new Map<String, dynamic>.from(snapshot.value);
Works perfect for me.
as doesn't change the type, it's just an assertion.
You need to use map['eventType'].cast<String, dynamic>()
or Map<String, dynamic>.from(map['eventType'])
You can also solved by this way:
Map<String, dynamic> myMap = new Map<String, dynamic>.from(/*Your Source*/ );