Address.fromJson constructor

Address.fromJson(
  1. Map<String, dynamic> json
)

Implementation

factory Address.fromJson(Map<String, dynamic> json) {
  // Support both snake_case (API) and camelCase formats
  return Address(
    id: json['id'] as String?,
    type: json['type'] as String?,
    firstName: json['firstName'] as String? ?? json['first_name'] as String?,
    lastName: json['lastName'] as String? ?? json['last_name'] as String?,
    company: json['company'] as String?,
    address1: json['address1'] as String? ?? json['address_1'] as String?,
    address2: json['address2'] as String? ?? json['address_2'] as String?,
    city: json['city'] as String?,
    state: json['state'] as String?,
    stateCode: json['stateCode'] as String? ?? json['state_code'] as String?,
    postalCode: json['postalCode'] as String? ?? json['postcode'] as String?,
    country: json['country'] != null
        ? (json['country'] is Map
            ? Country.fromJson(json['country'] as Map<String, dynamic>)
            : Country(code: json['country'] as String, name: json['country'] as String))
        : null,
    phone: json['phone'] as String?,
    email: json['email'] as String?,
    latitude: json['latitude'] as double?,
    longitude: json['longitude'] as double?,
    isDefault: json['isDefault'] as bool? ?? json['is_default'] as bool? ?? false,
    isVerified: json['isVerified'] as bool? ?? json['is_verified'] as bool? ?? false,
    instructions: json['instructions'] as String?,
    formattedAddress: json['formattedAddress'] as String? ?? json['formatted_address'] as String?,
    extensions: json['extensions'] as Map<String, dynamic>?,
  );
}