Hello Guys How are you all? Hope You all are fine. When I was trying to run my flutter app and suddenly I get the following error in my stack track. Error: List is not a subtype of type Map in a flutter. So today Here I come with all possible solutions for this error.
We are providing you all possible solutions to solve this error. let’s start this article without wasting your time.
How Error: List dynamic is not a subtype of type Map String, dynamic Occurs ?
I have List of json String Then I convert Json String to json list and I am trying to assing json list to List variable But got following error.
Error type 'List<dynamic>' is not a subtype of type 'Map<String, dynamic>'
How to Solve Error: List dynamic is not a subtype of type Map String, dynamic?
Question:
Answer:
- How to Solve Error: List dynamic is not a subtype of type Map String, dynamic?
To solve Error: List is not a subtype of type Map this means the data which you are receiving after hitting a web service is in form of a List but inside the data class which you have used is of type Map. So, it is not able to parse the data due to structure mismatch as Map is defined in instead of List in data class.
- Error: List dynamic is not a subtype of type Map String, dynamic
To solve Error: List is not a subtype of type Map this means the data which you are receiving after hitting a web service is in form of a List but inside the data class which you have used is of type Map. So, it is not able to parse the data due to structure mismatch as Map is defined in instead of List in data class.
Solution 1: Use List.from
Just look This example to solve your error.
var usersDataFromJson = parsedJson['data'];
List<String> userData = List<String>.from(usersDataFromJson);
Now you can use userData as List. So all you need to do is just add your json list into List.from();
Solution 2: Recheck your Json response and corresponding PODO class
basically, this error means the data which you are receiving after hitting a web service is in form of a List but inside the data class which you have used is of type Map. So, it is not able to parse the data due to structure mismatch as Map is defined in instead of List in data class.
Summery
So, It’s All About This Error. I hope this tutorial helps you to Solve your error. Please Comment Below if You stucks anywhere with my code. And please comment below on which solution worked for you. Thank You.
Also Check Out Below Tutorials
- Error: The getter ‘addressOf’ isn’t defined for the class ‘Utf8’
- Flutter insecure HTTP is not allowed by platform
- warning: The iOS deployment target ‘IPHONEOS_DEPLOYMENT_TARGET’ is set to 8.0
- Message “flutter run: No connected devices”
- Dart SDK is not configured