Fix DeliveryAddress parser to handle string IDs from API

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
John Mizerek 2026-01-23 21:05:56 -08:00
parent ce8cc74e96
commit 28e41a445e

View file

@ -1513,18 +1513,20 @@ class DeliveryAddress {
}); });
factory DeliveryAddress.fromJson(Map<String, dynamic> json) { factory DeliveryAddress.fromJson(Map<String, dynamic> json) {
final rawId = json["AddressID"] ?? json["ADDRESSID"] ?? 0;
final rawStateId = json["StateID"] ?? json["STATEID"] ?? 0;
return DeliveryAddress( return DeliveryAddress(
addressId: (json["AddressID"] ?? json["ADDRESSID"] ?? 0) as int, addressId: rawId is int ? rawId : int.tryParse(rawId.toString()) ?? 0,
label: (json["Label"] ?? json["LABEL"] ?? "Address") as String, label: (json["Label"] ?? json["LABEL"] ?? "Address").toString(),
isDefault: (json["IsDefault"] ?? json["ISDEFAULT"] ?? false) == true, isDefault: (json["IsDefault"] ?? json["ISDEFAULT"] ?? false) == true,
line1: (json["Line1"] ?? json["LINE1"] ?? "") as String, line1: (json["Line1"] ?? json["LINE1"] ?? "").toString(),
line2: (json["Line2"] ?? json["LINE2"] ?? "") as String, line2: (json["Line2"] ?? json["LINE2"] ?? "").toString(),
city: (json["City"] ?? json["CITY"] ?? "") as String, city: (json["City"] ?? json["CITY"] ?? "").toString(),
stateId: (json["StateID"] ?? json["STATEID"] ?? 0) as int, stateId: rawStateId is int ? rawStateId : int.tryParse(rawStateId.toString()) ?? 0,
stateAbbr: (json["StateAbbr"] ?? json["STATEABBR"] ?? "") as String, stateAbbr: (json["StateAbbr"] ?? json["STATEABBR"] ?? "").toString(),
stateName: (json["StateName"] ?? json["STATENAME"] ?? "") as String, stateName: (json["StateName"] ?? json["STATENAME"] ?? "").toString(),
zipCode: (json["ZIPCode"] ?? json["ZIPCODE"] ?? "") as String, zipCode: (json["ZIPCode"] ?? json["ZIPCODE"] ?? "").toString(),
displayText: (json["DisplayText"] ?? json["DISPLAYTEXT"] ?? "") as String, displayText: (json["DisplayText"] ?? json["DISPLAYTEXT"] ?? "").toString(),
); );
} }
} }