class ContactDetail { final int id; final dynamic name; final dynamic email; final dynamic phone; final dynamic image1920; final dynamic street; final dynamic street2; final dynamic city; final dynamic country; ContactDetail({ required this.id, required this.name, required this.email, required this.phone, required this.image1920, required this.street, required this.street2, required this.city, required this.country, }); factory ContactDetail.fromJson(Map json) { getCountry(){ if (json['country_id'] != null){ return json['country_id']['name']; } else{ return null; } } return ContactDetail( id: json['id'], name: json['name'], email: json['email'], phone: json['phone'], image1920: json['image_1920'], street: json['street'], street2: json['street2'], city: json['city'], country: getCountry(), ); } Map toJson() { return { 'id': id, 'name': name, 'email': email, 'phone': phone, 'image1920': image1920, 'street': street, 'street2': street2, 'city': city, 'country': country, }; } }