'flutter error : Expected a value of type 'int' but got one of type 'Null'
response body from the .NET Core 6 API :
[{"establishmentId":1,"establishmentName":"Secret","addressId":1,"documentationId":1,"address":null,"documentation":null,"associationsEts":[],"prices":[]},{"establishmentId":2,"establishmentName":"HRB","addressId":2,"documentationId":2,"address":null,"documentation":null,"associationsEts":[],"prices":[]}]
My model class :
class Establishment {
final int id;
final String name;
final int addressid;
final int documentationid;
Establishment(
{required this.id,
required this.name,
required this.addressid,
required this.documentationid});
factory Establishment.fromJson(Map<String, dynamic> json) {
return Establishment(
id: json['id'],
name: json['name'],
addressid: json['addressid'],
documentationid: json['documantationid']);
}
}
The problem is that snapshot got an error , I would like snapshot to accept null values, could someone help me to fix this ? Thanks
UPDATE :
The problem doesn't occurs in the from json beacuase since I modified them, the probelm still occurs
class Establishment {
final int establishmentId;
final String establishmentName;
final int addressId;
final int documentationId;
Establishment(
{required this.establishmentId,
required this.establishmentName,
required this.addressId,
required this.documentationId});
factory Establishment.fromJson(Map<String, dynamic> json) {
return Establishment(
establishmentId: json['establishmentId'],
establishmentName: json['establishmentName'],
addressId: json['addressId'],
documentationId: json['documantationId']);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
