type 'List<dynamic>' is not a subtype of type 'List<Map<String, String>>'
This error message usually occurs when trying to assign a List
Here's an example:
List<dynamic> dynamicList = [ {"name": "John", "age": 30}, {"name": "Mary", "age": 25} ];
List<Map<String, String>> stringMapList = dynamicList; // Error occurs here
In the above code, we have a ListdynamicList that contains two Map objects with string keys and dynamic values. We then try to assign dynamicList to a variable called stringMapList, which expects a List<Map<String, String>> object.
However, since dynamicList is a ListdynamicList will have string values, which is what stringMapList expects.
To fix this error, we need to convert the dynamic objects in dynamicList to Map objects with string values. We can do this using the cast() method:
List<dynamic> dynamicList = [ {"name": "John", "age": 30}, {"name": "Mary", "age": 25} ];
List<Map<String, String>> stringMapList = dynamicList.cast<Map<String, String>>();
In the above code, we use the cast() method to convert dynamicList to a List<Map<String, String>> object. This ensures that all the objects in the list are Map objects with string keys and values, which is what stringMapList expects.
原文地址: http://www.cveoy.top/t/topic/BYh 著作权归作者所有。请勿转载和采集!