Unhandled Exception type Map (String, dynamic) is not subtype of String? Flutter

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
and under exception type map string Dynamic is not a subtype of string now what it is trying to tell you is that okay I have a type here this map type is not a subtype of string and at the same time it's trying to point over here well as the pointing starts from here well of course this is an API call rest API call and then here it says from Json and if you click inside this from Json method here actually it would point to this place over here now in our case actually if you see data this data is actually a string and that's what it's pointed and found over here string optional the problem is over here it is expecting this section to be string so that it can assign to this filled data which is this one but what is getting from server is map so that is the problem okay I mean uh this is a response based response entity is a model now this data field wants response from the server itself for this data field over here as a string but I'm getting it a map so that's why the problem is happening now how to solve this issue now to solve this issue two ways to go one convert this data to map but which we don't want because this is our model whatever happens from server comes to us we want it to follow this model and this map over here whatever we have as a class we don't want to change so something is coming from server that is not correct okay now let's look at our server response what is server getting us but from here we can definitely see that this Json data is not a string it's a map and that's what it's trying to tell you okay so if you see this kind of error you have to confirm with your model model class and then the fields okay our field is data data is a string okay now it is getting mapped so let's go ahead and check our backend now the backend code is this one uh sorry not this one the backend code is this one now this is the problem actually now if I go ahead and try and Postman it will return us something like this so here you see this data is returning actually over here a map okay but on a front end we are supposed to have something for this data field which is this one as a string okay so how to solve this issue to solve it actually it's very easy just come over here instead of returning this one because we know we just learned that this one is returning at map so we don't want to return map in this case so we want to return a string it could be any string or it could be an empty string it doesn't matter but in my case I just say empty screen empty string and that's all okay now first let's confirm with this one over here okay we have empty string all right now over here let's go back and let's click on this and let's try on this yes beautiful this time our app doesn't crash and we say we see that it says payment failed now of course this payment fill is a message that's coming from here because our status code is not 200 anymore right now the code itself this code the one is our custom code which is not 200 uh which is over here it's a 400 but we are expecting 200 so we didn't get 200 so we just simply say okay you payment failed and that's beautiful
Info
Channel: dbestech
Views: 11,484
Rating: undefined out of 5
Keywords: Unhandled Exception type '_Map String dynamic ' is not a subtype of type String, type 'string' is not a subtype of type 'map string, dynamic ' in type cast
Id: yNLcZrFWdao
Channel Id: undefined
Length: 3min 58sec (238 seconds)
Published: Fri Jun 02 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.