I have data response with api and i can't map it to List but it return users null, i think is not working because method fromJson
this is data return with api
and this is my models
My controller
end is Debug window
Thanks for any answer
Could you further specify what it is that you get as a result? Is the whole list full of null? Or are some of the objects' fields null?
Here is what I believe is an error:
nameUser: json['tenNguoiDung'] == null ? '' : json['ten'] avatarUser: json['nguoiDung_anhDinhKem'] == null ? '' : json['avatar'],
You are saying:
If tenNguoiDung is null: nameUser is equal to '', if it isn't, nameUser = json['ten'].
tenNguoiDung
But your json doesn't have a 'ten' field, so it will be null. What you are most likely looking for is the if-null operator:
nameUser: json['tenNguoiDung'] ?? '' avatarUser: json['nguoiDung_anhDinhKem'] ?? ''
which will assign '' if the json field is null.
''
Could you further specify what it is that you get as a result? Is the whole list full of null? Or are some of the objects' fields null?
Here is what I believe is an error:
You are saying:
But your json doesn't have a 'ten' field, so it will be null. What you are most likely looking for is the if-null operator:
which will assign
''
if the json field is null.