taafee-mobile/lib/features/card/data_layer/model/edit_card.dart
2023-10-17 17:22:55 +03:00

87 lines
2.0 KiB
Dart

import 'dart:io';
import 'package:dio/dio.dart';
class EditCardModel {
String? name;
int? categoryId;
int? cityId;
int? cardId;
String? phoneNumber;
String? address;
String? postalCode;
String? webSite;
String? service;
String? additionalData;
List<File>? images;
EditCardModel(
{this.name,
this.categoryId,
this.cityId,
this.phoneNumber,
this.address,
this.postalCode,
this.webSite,
this.service,
this.additionalData,
this.images});
Map<String, dynamic> toJson() {
Map<String, dynamic> result = {
// "name": name,
// "city_id": cityId,
// "category_id": categoryId,
// "phone_number1": phoneNumber,
// "website": webSite,
// "services": service,
// "additional_data": additionalData,
};
if (name != null && name != "") {
result["name"] = name;
}
if (cityId != null && cityId != 0) {
result["city_id"] = cityId;
}
if (categoryId != null && categoryId != 0) {
result["category_id"] = categoryId;
}
if (phoneNumber != null && phoneNumber != "") {
result["phone_number1"] = phoneNumber;
}
if (webSite != null && webSite != "") {
result["website"] = webSite;
}
if (service != null && service != "") {
result["services"] = service;
}
if (additionalData != null && additionalData != "") {
result["additional_data"] = additionalData;
}
if (address != null && postalCode != " ") {
result["address"] = address;
}
if (postalCode != null && postalCode != " ") {
result["postal_code"] = postalCode;
}
return result;
}
Map<String, dynamic> imagesAddingData() {
Map<String, dynamic> imagesAddingMap = {
'card_id': cardId,
};
if (images != null) {
for (int i = 0; i < images!.length; i++) {
imagesAddingMap["images[${i + 1}]"] =
MultipartFile.fromFileSync(images![i].path);
}
}
return imagesAddingMap;
}
factory EditCardModel.zero() => EditCardModel();
}