import 'package:get/get.dart'; class CityModel { int id; String enName; String cnName; String arName; String enCountry; String cnCountry; String arCountry; int countryId; String get name { String locale = Get.locale!.languageCode; switch (locale) { case 'ar': return arName; case 'en': return enName; case 'cn': return cnName; } return enName; } String get country { String locale = Get.locale!.languageCode; switch (locale) { case 'ar': return arCountry; case 'en': return enCountry; case 'cn': return cnCountry; } return enName; } CityModel({ required this.id, required this.enName, required this.cnName, required this.arName, required this.arCountry, required this.cnCountry, required this.enCountry, required this.countryId, }); factory CityModel.fromJson(Map json) => CityModel( id: json["id"], enName: json["en_name"], cnName: json["cn_name"], arName: json["ar_name"], countryId: json["country_id"], arCountry: json["country_ar"], enCountry: json["country_en"], cnCountry: json["country_cn"], ); factory CityModel.zero() => CityModel( id: 0, enName: 'city'.tr, cnName: 'city'.tr, arName: 'city'.tr, arCountry: '', cnCountry: '', enCountry: '', countryId: 0); static List fromJsonList(Map json) { List cities = []; json["data"].forEach( (element) => cities.add( CityModel.fromJson(element), ), ); return cities; } bool compare(CityModel cityModel) { if (id == cityModel.id) { return true; } if (name == cityModel.name) { return true; } if (countryId == cityModel.countryId) { return true; } if (country == cityModel.country) { return true; } else { return false; } } }