flutter error : Expected a value of type 'int' but got one of type 'Null'

flutter error : Expected a value of type 'int' but got one of type 'Null'

来自 .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":[]}]

我的模型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']);
      }
    }

问题是快照出错,我希望快照接受空值,有人可以帮我解决这个问题吗? 谢谢

更新:

问题没有出现在json因为我修改了它们,问题仍然出现

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']);
  }
}

你的"fromJson"解析出现错误,将你的factory fromJson函数替换成这样:

factory Establishment.fromJson(Map<String, dynamic> json) {
        return Establishment(
            id: json['establishmentId'],
            name: json['establishmentName'],
            addressid: json['addressId'],
            documentationid: json['documentationId']);
      }

提示:检查 camelCase 名称,名称在解析时必须相等。