I TRIED USING MAP TO COLLECT DATA BUT IT DOESN'T WORK EITHER I AM TRYING TO GET LIST OF PRICE FROM REST API USING GETX IN FLUTTER BUT RESULTING TO THE ERROR BELOW SAYING CAST ERROR ON LOADING APP
CodePudding user response:
your jsonResponse is not List, it is Map, I call your request and it getting Unauthorized error. I think you should fix that first
CodePudding user response:
You are receiving a map and trying to parse in as a List. Thats what the error is telling you.
I would approach this by creating a model class for the and serialising the data there.
class User {
final String name;
final String email;
User(this.name, this.email);
User.fromJson(Map<String, dynamic> json)
: name = json['name'],
email = json['email'];
Map<String, dynamic> toJson() => {
'name': name,
'email': email,
};
}
example from flutter docs