import 'package:taafee_mobile/features/home/data_layer/model/city.dart'; import 'card_images.dart'; import '../../../auth/data_layer/model/user.dart'; class CardModel { int id; String name; CityModel cityModel; String? address; String? postalCode; String phoneNumber; String services; int categoryId; User user; String website; String additionalData; List cardImages; bool isFav; CardModel( {required this.id, required this.name, required this.cityModel, this.address, this.postalCode, required this.phoneNumber, required this.services, required this.categoryId, required this.user, required this.website, required this.additionalData, required this.cardImages, required this.isFav}); factory CardModel.fromJson(Map json) => CardModel( id: json["id"], name: json["name"], cityModel: CityModel.fromJson(json["city"]), address: json["address"], postalCode: json["postal_code"], phoneNumber: json["phone_number1"], services: json["services"], categoryId: json["category_id"] ?? json['category']['id'], user: User.fromJson(json["user"]), website: json["website"], additionalData: json["additional_data"], cardImages: CardImages.fromJsonList(json), isFav: json["isFav"] == 1 ? true : false); static List fromJsonList(Map json) { List cards = []; // ignore: avoid_function_literals_in_foreach_calls json["data"].forEach( (element) => cards.add( CardModel.fromJson(element), ), ); return cards; } }