From aaa8f68e6026272d11f7f09190def5a33d1cc3dc Mon Sep 17 00:00:00 2001 From: Aamir Date: Thu, 5 Dec 2024 12:39:30 +0300 Subject: [PATCH] fixes --- assets/langs/ar-SA.json | 6 +- assets/langs/en-US.json | 6 +- lib/classes/consts.dart | 8 + lib/generated/codegen_loader.g.dart | 12 +- lib/generated/locale_keys.g.dart | 4 + .../profile/document.dart | 102 ++++--- lib/models/user_models/user.dart | 9 + lib/repositories/branch_repo.dart | 1 + lib/services/common_services.dart | 36 ++- lib/utils/location/Location.dart | 3 +- lib/view_models/ad_view_model.dart | 18 ++ lib/view_models/chat_view_model.dart | 5 + lib/view_models/requests_view_model.dart | 7 + lib/view_models/service_view_model.dart | 33 +-- lib/view_models/user_view_model.dart | 24 +- .../provider_license_page.dart | 269 ++++++++++-------- lib/views/user/register_page.dart | 1 - lib/views/user/update_user_city_country.dart | 100 ++++--- lib/views/user/update_user_details.dart | 4 +- 19 files changed, 419 insertions(+), 229 deletions(-) diff --git a/assets/langs/ar-SA.json b/assets/langs/ar-SA.json index e65240d..e1eed1a 100644 --- a/assets/langs/ar-SA.json +++ b/assets/langs/ar-SA.json @@ -750,7 +750,11 @@ "updateCity": "تحديث المدينة", "userGender": "جنس", "userMale": "ذكر", - "userFemale": "أنثى" + "userFemale": "أنثى", + "maxFileSelection" :"يمكنك تحديد الحد الأقصى لملفات 7", + "maxFileSize": "يجب أن يكون حجم كل ملف أقل من 2 ميغابايت", + "onlyJPGandPNG": "يُسمح فقط بملفات JPG وPNG", + "expiryDate": "تاريخ انتهاء الصلاحية" } \ No newline at end of file diff --git a/assets/langs/en-US.json b/assets/langs/en-US.json index 65eea5d..8d55a7b 100644 --- a/assets/langs/en-US.json +++ b/assets/langs/en-US.json @@ -748,5 +748,9 @@ "updateCity": "Update City", "userGender": "Gender", "userMale": "Male", - "userFemale": "Female" + "userFemale": "Female", + "maxFileSelection" :"You can select a maximum of 7 files", + "maxFileSize": "Each file size must be less than 2 MB", + "onlyJPGandPNG": "Only JPG and PNG files are allowed", + "expiryDate": "Expiry Date" } \ No newline at end of file diff --git a/lib/classes/consts.dart b/lib/classes/consts.dart index a7a73f3..5a97810 100644 --- a/lib/classes/consts.dart +++ b/lib/classes/consts.dart @@ -253,6 +253,12 @@ class GlobalConsts { } return appInvitationMessageEn; } + + + // Attachment Values + + int maxFileCount = 7; + int maxFileSizeInBytes = 2 * 1024 * 1024; } class MyAssets { @@ -394,4 +400,6 @@ class SignalrConsts { // General static String sendMessageGeneral = "SendMessageGeneral"; static String receiveMessageGeneral = "ReceiveMessageGeneral"; + + } diff --git a/lib/generated/codegen_loader.g.dart b/lib/generated/codegen_loader.g.dart index 6a25b80..bd7c9f3 100644 --- a/lib/generated/codegen_loader.g.dart +++ b/lib/generated/codegen_loader.g.dart @@ -766,7 +766,11 @@ class CodegenLoader extends AssetLoader{ "updateCity": "تحديث المدينة", "userGender": "جنس", "userMale": "ذكر", - "userFemale": "أنثى" + "userFemale": "أنثى", + "maxFileSelection": "يمكنك تحديد الحد الأقصى لملفات 7", + "maxFileSize": "يجب أن يكون حجم كل ملف أقل من 2 ميغابايت", + "onlyJPGandPNG": "يُسمح فقط بملفات JPG وPNG", + "expiryDate": "تاريخ انتهاء الصلاحية" }; static const Map en_US = { "firstTimeLogIn": "First Time Log In", @@ -1518,7 +1522,11 @@ static const Map en_US = { "updateCity": "Update City", "userGender": "Gender", "userMale": "Male", - "userFemale": "Female" + "userFemale": "Female", + "maxFileSelection": "You can select a maximum of 7 files", + "maxFileSize": "Each file size must be less than 2 MB", + "onlyJPGandPNG": "Only JPG and PNG files are allowed", + "expiryDate": "Expiry Date" }; static const Map> mapLocales = {"ar_SA": ar_SA, "en_US": en_US}; } diff --git a/lib/generated/locale_keys.g.dart b/lib/generated/locale_keys.g.dart index be7dc15..16cec03 100644 --- a/lib/generated/locale_keys.g.dart +++ b/lib/generated/locale_keys.g.dart @@ -730,5 +730,9 @@ abstract class LocaleKeys { static const userGender = 'userGender'; static const userMale = 'userMale'; static const userFemale = 'userFemale'; + static const maxFileSelection = 'maxFileSelection'; + static const maxFileSize = 'maxFileSize'; + static const onlyJPGandPNG = 'onlyJPGandPNG'; + static const expiryDate = 'expiryDate'; } diff --git a/lib/models/provider_branches_models/profile/document.dart b/lib/models/provider_branches_models/profile/document.dart index d82aa02..bea4d46 100644 --- a/lib/models/provider_branches_models/profile/document.dart +++ b/lib/models/provider_branches_models/profile/document.dart @@ -4,6 +4,8 @@ import 'dart:convert'; +import 'package:mc_common_app/utils/enums.dart'; + Document documentFromJson(String str) => Document.fromJson(json.decode(str)); String documentToJson(Document data) => json.encode(data.toJson()); @@ -21,16 +23,14 @@ class Document { int? messageStatus; String? message; - factory Document.fromJson(Map json) => - Document( + factory Document.fromJson(Map json) => Document( totalItemsCount: json["totalItemsCount"], data: json["data"] == null ? null : List.from(json["data"].map((x) => DocumentData.fromJson(x))), messageStatus: json["messageStatus"], message: json["message"], ); - Map toJson() => - { + Map toJson() => { "totalItemsCount": totalItemsCount, "data": data == null ? null : List.from(data!.map((x) => x.toJson())), "messageStatus": messageStatus, @@ -39,27 +39,29 @@ class Document { } class DocumentData { - DocumentData({ - this.id, - this.serviceProviderId, - this.documentId, - this.documentUrl, - this.status, - this.statusText, - this.comment, - this.isActive, - this.document, - this.fileExt, - this.documentName, - this.isLocalFile, - this.description, - }); + DocumentData( + {this.id, + this.serviceProviderId, + this.documentId, + this.documentUrl, + this.status, + this.statusText, + this.comment, + this.isActive, + this.document, + this.fileExt, + this.documentName, + this.isLocalFile, + this.description, + this.dateExpire, + this.isAllowUpdate, + this.isExpired}); int? id; int? serviceProviderId; int? documentId; String? documentUrl; - int? status; + DocumentStatusEnum? status; String? comment; bool? isActive; String? document; @@ -68,25 +70,29 @@ class DocumentData { String? documentName; bool? isLocalFile; String? description; + String? dateExpire; + bool? isExpired; + bool? isAllowUpdate; - factory DocumentData.fromJson(Map json) => - DocumentData( - id: json["id"], - serviceProviderId: json["serviceProviderID"], - documentId: json["documentID"], - documentUrl: json["documentURL"], - status: json["status"], - statusText: json["statusText"], - comment: json["comment"], - isActive: json["isActive"], - document: null, - fileExt: null, - documentName: json["documentName"], - isLocalFile: false, - description: null); + factory DocumentData.fromJson(Map json) => DocumentData( + id: json["id"], + serviceProviderId: json["serviceProviderID"], + documentId: json["documentID"], + documentUrl: json["documentURL"], + status: json.containsKey("status") ? (json['status'] as int).toDocumentStatusEnum() : null, + statusText: json["statusText"], + comment: json["comment"], + isActive: json["isActive"], + dateExpire: json["dateExpire"], + isExpired: json["isExpired"], + isAllowUpdate: json["isAllowUpdate"], + document: null, + fileExt: null, + documentName: json["documentName"], + isLocalFile: false, + description: null); - Map toJson() => - { + Map toJson() => { "id": id, "serviceProviderID": serviceProviderId, "documentID": documentId, @@ -94,5 +100,27 @@ class DocumentData { "status": status, "comment": comment, "isActive": isActive, + "dateExpire": dateExpire, + "isExpired": isExpired, + "isAllowUpdate": isAllowUpdate, }; } + +extension DocumentEnum on int { + DocumentStatusEnum toDocumentStatusEnum() { + switch (this) { + case 0: + return DocumentStatusEnum.needUpload; + case 1: + return DocumentStatusEnum.pending; + case 2: + return DocumentStatusEnum.review; + case 3: + return DocumentStatusEnum.approvedOrActive; + case 4: + return DocumentStatusEnum.rejected; + default: + throw Exception('Invalid status value: $this'); // Explicit handling for invalid cases + } + } +} diff --git a/lib/models/user_models/user.dart b/lib/models/user_models/user.dart index 659edaf..7c91069 100644 --- a/lib/models/user_models/user.dart +++ b/lib/models/user_models/user.dart @@ -82,6 +82,8 @@ class UserInfo { this.userImageUrl, this.roleId, this.roleName, + this.genderID, + this.genderName, this.isEmailVerified, this.serviceProviderBranch, this.isVerified, @@ -97,6 +99,7 @@ class UserInfo { this.userLocalImage, this.cityName, this.countryName, + }); int? id; @@ -105,6 +108,8 @@ class UserInfo { String? lastName; String? countryName; String? cityName; + int? genderID; + String? genderName; String? mobileNo; String? email; dynamic userImageUrl; @@ -139,6 +144,8 @@ class UserInfo { firstName = json["firstName"]; lastName = json["lastName"]; cityName = json["cityName"]; + genderID = json["genderID"]; + genderName = json["genderName"]; countryName = json["countryName"]; mobileNo = json["mobileNo"]; email = json["email"]; @@ -205,6 +212,8 @@ class UserInfo { "providerID": providerId, "customerID": customerId, "dealershipID": dealershipId, + "genderName": genderName, + "genderID": genderID }; @override diff --git a/lib/repositories/branch_repo.dart b/lib/repositories/branch_repo.dart index 2cb2f77..6375ee0 100644 --- a/lib/repositories/branch_repo.dart +++ b/lib/repositories/branch_repo.dart @@ -208,6 +208,7 @@ class BranchRepoImp implements BranchRepo { "documentExt": documents[i].fileExt, "documentImage": documents[i].document, "isActive": true, + "dateExpire":documents[i].dateExpire, }; map.add(postParams); } diff --git a/lib/services/common_services.dart b/lib/services/common_services.dart index c80988d..ccc77ea 100644 --- a/lib/services/common_services.dart +++ b/lib/services/common_services.dart @@ -4,6 +4,8 @@ import 'package:file_picker/file_picker.dart'; import 'package:flutter/material.dart'; import 'package:geolocator/geolocator.dart'; import 'package:image_picker/image_picker.dart'; +import 'package:mc_common_app/classes/consts.dart'; +import 'package:mc_common_app/generated/locale_keys.g.dart'; import 'package:mc_common_app/main.dart'; import 'package:mc_common_app/utils/app_permission_handler.dart'; import 'package:mc_common_app/utils/utils.dart'; @@ -56,21 +58,35 @@ class CommonServicesImp implements CommonAppServices { return pickedFiles; } - @override + + Future> pickMultipleImages() async { final picker = ImagePicker(); - final pickedImagesXFiles = await picker.pickMultiImage(); - + List imageModels = []; List pickedImages = []; - if (pickedImagesXFiles == null) { - return []; - } - if (pickedImagesXFiles.isEmpty) { - return []; + var images = await picker.pickMultiImage(imageQuality: 70); + + for (var element in images) { + final extension = element.path.split('.').last.toLowerCase(); + + if (extension != 'jpg' && extension != 'jpeg' && extension != 'png') { + Utils.showToast(LocaleKeys.onlyJPGandPNG); + return []; + } + + if (await element.length() > GlobalConsts().maxFileSizeInBytes) { + Utils.showToast(LocaleKeys.maxFileSize); + return []; + } + imageModels.add(File(element.path)); } - for (var element in pickedImagesXFiles) { - pickedImages.add(File(element.path)); + + if (imageModels.length > GlobalConsts().maxFileCount) { + Utils.showToast(LocaleKeys.maxFileSelection); + imageModels = imageModels.sublist(0, GlobalConsts().maxFileCount); // Keep only the first 7 images } + + pickedImages.addAll(imageModels); return pickedImages; } diff --git a/lib/utils/location/Location.dart b/lib/utils/location/Location.dart index 0b08abe..5d2260d 100644 --- a/lib/utils/location/Location.dart +++ b/lib/utils/location/Location.dart @@ -81,7 +81,8 @@ class LocationService implements Location { if (granted) { Geolocator.getLastKnownPosition(forceAndroidLocationManager: true).then((value) { if (value == null) { - Geolocator.getCurrentPosition().then((value) { + Geolocator.getCurrentPosition().then((value) async { + if(value == null) await Geolocator.openAppSettings(); done(value); }); } else { diff --git a/lib/view_models/ad_view_model.dart b/lib/view_models/ad_view_model.dart index 76b0f09..6f1cf99 100644 --- a/lib/view_models/ad_view_model.dart +++ b/lib/view_models/ad_view_model.dart @@ -1194,7 +1194,14 @@ class AdVM extends BaseVM { for (var element in images) { imageModels.add(ImageModel(filePath: element.path, isFromNetwork: false)); } + pickedPostingImages.addAll(imageModels); + // Added By Aamir + if (pickedPostingImages.length > GlobalConsts().maxFileCount) { + pickedPostingImages = pickedPostingImages.sublist(0, GlobalConsts().maxFileCount); + Utils.showToast(LocaleKeys.maxFileSelection); + } + if (pickedPostingImages.isNotEmpty) vehicleImageError = ""; notifyListeners(); } @@ -1237,7 +1244,13 @@ class AdVM extends BaseVM { vehicleDamageCards[index].partImages = imageModels; } else { vehicleDamageCards[index].partImages!.addAll(imageModels); +// Added By Aamir + if (vehicleDamageCards[index].partImages!.length > GlobalConsts().maxFileCount) { + vehicleDamageCards[index].partImages = vehicleDamageCards[index].partImages!.sublist(0, GlobalConsts().maxFileCount); + Utils.showToast(LocaleKeys.maxFileSelection); + } } + vehicleDamageCards[index].partImageErrorValue = ""; notifyListeners(); } @@ -1287,6 +1300,11 @@ class AdVM extends BaseVM { void pickMultipleDamageImages() async { List images = await commonServices.pickMultipleImages(); pickedDamageImages.addAll(images); + + if (pickedDamageImages.length > GlobalConsts().maxFileCount) { + pickedDamageImages = pickedDamageImages.sublist(0, GlobalConsts().maxFileCount); + Utils.showToast(LocaleKeys.maxFileSelection); + } if (pickedDamageImages.isNotEmpty) vehicleDamageImageError = ""; notifyListeners(); } diff --git a/lib/view_models/chat_view_model.dart b/lib/view_models/chat_view_model.dart index f558cf5..9ea2a21 100644 --- a/lib/view_models/chat_view_model.dart +++ b/lib/view_models/chat_view_model.dart @@ -406,6 +406,11 @@ class ChatVM extends BaseVM { imageModels.add(ImageModel(filePath: element.path, isFromNetwork: false)); } pickedImagesForMessage.addAll(imageModels); + if (pickedImagesForMessage.length > GlobalConsts().maxFileCount) { + pickedImagesForMessage = pickedImagesForMessage.sublist(0, GlobalConsts().maxFileCount); + Utils.showToast(LocaleKeys.maxFileSelection); + } + notifyListeners(); } diff --git a/lib/view_models/requests_view_model.dart b/lib/view_models/requests_view_model.dart index 079cd9a..7df80f6 100644 --- a/lib/view_models/requests_view_model.dart +++ b/lib/view_models/requests_view_model.dart @@ -231,10 +231,17 @@ class RequestsVM extends BaseVM { imageModels.add(ImageModel(filePath: element.path, isFromNetwork: false)); } pickedVehicleImages.addAll(imageModels); + if (pickedVehicleImages.length > GlobalConsts().maxFileCount) { + pickedVehicleImages = pickedVehicleImages.sublist(0, GlobalConsts().maxFileCount); + Utils.showToast(LocaleKeys.maxFileSelection); + } + if (pickedVehicleImages.isNotEmpty) vehicleImageError = ""; notifyListeners(); } + + bool isFetchingRequestType = false; bool isFetchingVehicleType = true; bool isFetchingVehicleDetail = false; diff --git a/lib/view_models/service_view_model.dart b/lib/view_models/service_view_model.dart index 1068494..933cc2c 100644 --- a/lib/view_models/service_view_model.dart +++ b/lib/view_models/service_view_model.dart @@ -132,6 +132,10 @@ class ServiceVM extends BaseVM { imageModels.add(ImageModel(filePath: element.path, isFromNetwork: false)); } pickedBranchImages.addAll(imageModels); + if (pickedBranchImages.length > GlobalConsts().maxFileCount) { + pickedBranchImages = pickedBranchImages.sublist(0, GlobalConsts().maxFileCount); + Utils.showToast(LocaleKeys.maxFileSelection); + } if (pickedBranchImages.isNotEmpty) branchImageError = ""; notifyListeners(); } @@ -201,7 +205,6 @@ class ServiceVM extends BaseVM { } branchServicesFilterOptions[serviceStatusEnum.getIdFromServiceStatusEnum() - 1].isSelected = true; // -1 to match with the index - } // Future selectFile(BuildContext context, int index) async { @@ -264,11 +267,7 @@ class ServiceVM extends BaseVM { context, allowMultiple: false, ); - if (files != null && files.any((element) => - element.path - .split('.') - .last - .toLowerCase() != 'pdf')) { + if (files != null && files.any((element) => element.path.split('.').last.toLowerCase() != 'pdf')) { Utils.showToast("Only PDF Files are allowed"); return; } @@ -279,11 +278,11 @@ class ServiceVM extends BaseVM { isFromNetwork: false, )); } - documentID == 1 - ? commerceCertificates.addAll(imageModels) - : documentID == 2 - ? commercialCertificates.addAll(imageModels) - : vatCertificates.addAll(imageModels); + // documentID == 1 + // ? commerceCertificates.addAll(imageModels) + // : documentID == 2 + // ? commercialCertificates.addAll(imageModels) + // : vatCertificates.addAll(imageModels); document!.data![index].document = Utils.convertFileToBase64(files.first); document!.data![index].fileExt = Utils.checkFileExt(files.first.path); document!.data![index].documentUrl = files.first.path; @@ -459,10 +458,10 @@ class ServiceVM extends BaseVM { DropValue( element.id ?? 0, ((element.categoryName!.isEmpty - ? "N/A" - : countryCode == "SA" - ? element.categoryNameN - : element.categoryName) ?? + ? "N/A" + : countryCode == "SA" + ? element.categoryNameN + : element.categoryName) ?? "N/A"), "", ), @@ -657,9 +656,7 @@ class ServiceVM extends BaseVM { File file = File(imageModel.filePath!); List imageBytes = await file.readAsBytes(); String image = base64Encode(imageBytes); - String fileName = file.path - .split('/') - .last; + String fileName = file.path.split('/').last; branchPostingImages = BranchPostingImages( imageName: fileName, imageStr: image, diff --git a/lib/view_models/user_view_model.dart b/lib/view_models/user_view_model.dart index d06f1c6..6a2bd38 100644 --- a/lib/view_models/user_view_model.dart +++ b/lib/view_models/user_view_model.dart @@ -170,7 +170,7 @@ class UserVM extends BaseVM { } } - Future userDetailsUpdate(BuildContext context, String firstName, String lastName, String? city) async { + Future userDetailsUpdate(BuildContext context, String firstName, String lastName, String? city, String? cityName, String? countryName) async { Utils.showLoading(context); Map res = await userRepo.updateUserInfo(firstName, lastName, city); Utils.hideLoading(context); @@ -180,6 +180,13 @@ class UserVM extends BaseVM { if (localUser.data != null) { localUser.data!.userInfo!.firstName = res["data"]["firstName"]; localUser.data!.userInfo!.lastName = res["data"]["lastName"]; + localUser.data!.userInfo!.cityId = res["data"]["cityID"]; + localUser.data!.userInfo!.countryId = res["data"]["countryID"]; + if (cityName != null && countryName != null) { + localUser.data!.userInfo!.cityName = cityName; + localUser.data!.userInfo!.countryName = countryName; + } + // localUser.data!.userInfo!.cityId = res["data"]["cityId"]; AppState().setUser = localUser; } @@ -205,7 +212,15 @@ class UserVM extends BaseVM { if (Utils.passwordValidateStructure(password)) { if (password == confirmPassword) { Utils.showLoading(context); - RegisterUserRespModel user = await userRepo.basicComplete(userId ?? "", firstName, lastName, email, password, cityID, genderID, isNeedToPassToken: isNeedToPassToken); + RegisterUserRespModel user = await userRepo.basicComplete( + userId ?? "", + firstName, + lastName, + email, + password, + cityID, + genderID, + isNeedToPassToken: isNeedToPassToken); Utils.hideLoading(context); if (user.messageStatus == 1) { Utils.showToast(LocaleKeys.successfullyRegistered.tr()); @@ -253,8 +268,7 @@ class UserVM extends BaseVM { Utils.showToast(LocaleKeys.pleaseAcceptTerms.tr()); //("Please accept terms"); isValid = false; - } - else if (city == null) { + } else if (city == null) { Utils.showToast(LocaleKeys.cityNameMandatory.tr()); isValid = false; } else if (gender == null) { @@ -591,6 +605,8 @@ class UserVM extends BaseVM { } Future getAllCountriesForUser() async { + userCountries = null; + userCities = null; userCountries = await userRepo.getAllCountries(); notifyListeners(); } diff --git a/lib/views/setting_options/provider_license_page.dart b/lib/views/setting_options/provider_license_page.dart index 103cd26..d4501fc 100644 --- a/lib/views/setting_options/provider_license_page.dart +++ b/lib/views/setting_options/provider_license_page.dart @@ -19,6 +19,7 @@ import 'package:mc_common_app/views/advertisement/ad_creation_steps/ad_creation_ import 'package:mc_common_app/views/advertisement/components/picked_images_container_widget.dart'; import 'package:mc_common_app/widgets/button/show_fill_button.dart'; import 'package:mc_common_app/widgets/common_widgets/app_bar.dart'; +import 'package:mc_common_app/widgets/common_widgets/search_entity_widget.dart'; import 'package:mc_common_app/widgets/extensions/extensions_widget.dart'; import 'package:mc_common_app/widgets/txt_field.dart'; @@ -35,6 +36,7 @@ class _ProviderLicensePageState extends State { late ServiceVM branchVM; bool showAttachment = false; String? attachedFile; + String? formattedDate; @override void initState() { @@ -50,7 +52,7 @@ class _ProviderLicensePageState extends State { if (model.document != null && model.document!.data != null && model.document!.data!.isNotEmpty) { for (var doc in model.document!.data!) { log("doc: ${doc.status}"); - if (doc.status == 4 || doc.status == 0) { + if (doc.status == DocumentStatusEnum.rejected || doc.status == DocumentStatusEnum.needUpload || doc.isAllowUpdate!) { isShow = true; } } @@ -162,6 +164,7 @@ class _ProviderLicensePageState extends State { padding: const EdgeInsets.symmetric(horizontal: 20), itemBuilder: (context, index) { DocumentData? document = serviceVM.document?.data![index]; + return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -172,40 +175,58 @@ class _ProviderLicensePageState extends State { (document!.documentName!).toText(fontSize: 16, letterSpacing: -0.56, fontWeight: MyFonts.SemiBold), if (document.statusText != null && document.statusText!.isNotEmpty) ...[ 10.width, - Utils.statusContainerChip(text: document.statusText!.replaceFirst('OrActive', ''), chipColor: getColorByStatus(document.status ?? 1)), + Utils.statusContainerChip(text: document.statusText!.replaceFirst('OrActive', ''), chipColor: getColorByStatus(document.status!)), ], ], ), - // if (document.status != 1 && document.status != 3) ...[ - // Padding( - // padding: const EdgeInsets.only(top: 4, bottom: 8), - // child: LocaleKeys.enter_licence_detail.tr().toText(fontSize: 14, color: MyColors.lightTextColor), - // ), - // TxtField( - // hint: LocaleKeys.description.tr(), - // maxLines: 3, - // isBackgroundEnabled: true, - // ), - // ], - 10.height, - if (isNeedToShow(model: serviceVM, document: document)) ...[ - PickedFilesContainer( - isReview: document.status != 0 && (document.status == 1 || document.status == 3), - allowAdButton: false, - pickedFiles: isLocalOrNetworkFiles(model: serviceVM, document: document), - onCrossPressedPrimary: isNetworkImage(document: document) - ? serviceVM.removeNetworkImage - : document.documentId == 1 - ? serviceVM.commerceRemove - : document.documentId == 2 - ? serviceVM.commercialRemove - : serviceVM.vatRemove, + if (document.documentUrl != null) ...[ + BuildFilesContainer( + image: ImageModel(id: index, filePath: document.documentUrl!, isFromNetwork: document.isLocalFile! ? false : true), + onCrossPressedPrimary: (String val) { + document.documentUrl = null; + document.isLocalFile = false; + setState(() {}); + }, + index: index, + isReview: isReview(document), isPdf: true, - isFromNetwork: !(document.isLocalFile ?? false), - onAddFilePressed: () { - serviceVM.pickPdfReceiptFile(context, document.documentId!, index); + ), + 5.height, + ("${document.documentName} Expiry").toText(fontSize: 14, letterSpacing: -0.56, fontWeight: MyFonts.Medium), + 5.height, + TxtField( + isBackgroundEnabled: (document.status == DocumentStatusEnum.pending || document.status == DocumentStatusEnum.approvedOrActive && !document.isAllowUpdate!), + isNeedBorder: document.isAllowUpdate! ? true : false, + isSidePaddingZero: true, + + hint: LocaleKeys.expiryDate.tr(), + value: document.dateExpire != null && document.status == DocumentStatusEnum.pending || document.status == DocumentStatusEnum.approvedOrActive ? "${DateFormat('yyyy-MM-dd').format( + DateTime.parse(document.dateExpire!))}" : formattedDate == null + ? "" + : "${DateFormat('yyyy-MM-dd').format(DateTime.parse(document.dateExpire!))}", + isNeedClickAll: true, + postFixDataColor: MyColors.darkTextColor, + onTap: () async { + if (document.isAllowUpdate! && document.status == DocumentStatusEnum.approvedOrActive || document.status == DocumentStatusEnum.needUpload || + document.status == DocumentStatusEnum.rejected) { + formattedDate = + await Utils.pickDateFromDatePicker(context, lastDate: DateTime(DateTime + .now() + .year + 3, DateTime + .now() + .month + 1, DateTime + .now() + .day), firstDate: DateTime.now()); + if (formattedDate!.isNotEmpty) { + document.dateExpire = formattedDate; + setState(() {}); + } + } + + // requestsVM.updateRequestedDate(formattedDate); }, ), + 10.height, buildCommentContainer(document: document), ] else ...[ @@ -215,107 +236,133 @@ class _ProviderLicensePageState extends State { text: LocaleKeys.attachPDF.tr(), icon: MyAssets.attachmentIcon.buildSvg(), ), - ], + ] ], ); }, ); } - List isLocalOrNetworkFiles({required ServiceVM model, required DocumentData document}) { - bool isNetworkImage = false; - - if (!document.isLocalFile!) { - isNetworkImage = document.documentUrl != null && document.documentUrl!.isNotEmpty ? true : false; + bool isReview(DocumentData document) { + print(document.toJson()); + bool val = false; + if (document.isAllowUpdate == null) { + val = false; } - if (isNetworkImage) { - return [ImageModel(id: document.id, isFromNetwork: isNetworkImage, filePath: document.documentUrl)]; - } else if (document.documentId == 1) { - return model.commerceCertificates; - } else if (document.documentId == 2) { - return model.commercialCertificates; - } else { - return model.vatCertificates; + if (document.isAllowUpdate! && document.status == DocumentStatusEnum.approvedOrActive) { + val = false; } - } - - bool isNeedToShow({required ServiceVM model, required DocumentData document}) { - bool allow = false; - bool isNetworkImage = document.documentUrl != null && document.documentUrl!.isNotEmpty && !(document.isLocalFile ?? true); - if (isNetworkImage) { - allow = true; - } else { - if (document.documentId == 1 && model.commerceCertificates.isNotEmpty) { - allow = true; - } - if (document.documentId == 2 && model.commercialCertificates.isNotEmpty) { - allow = true; - } - if (document.documentId == 3 && model.vatCertificates.isNotEmpty) { - allow = true; - } + if (!document.isAllowUpdate! && document.status == DocumentStatusEnum.approvedOrActive) { + val = true; } - return allow; - } - - dynamic checkOnCrossPress({required ServiceVM model, required DocumentData document}) async { - bool isNetworkImage = document.documentUrl != null && document.documentUrl!.isNotEmpty ? true : false; - if (isNetworkImage) { - return document.documentUrl; - } else { - if (document.documentId == 1) { - model.commerceRemove; - } - if (document.documentId == 2) { - model.commercialRemove; - } - if (document.documentId == 3) { - model.vatRemove; - } + if (document.isAllowUpdate! && document.status == DocumentStatusEnum.pending) { + val = true; } - } - - bool isNetworkImage({required DocumentData document}) { - bool isNetworkImage = false; - if (!document.isLocalFile!) { - isNetworkImage = document.documentUrl != null && document.documentUrl!.isNotEmpty ? true : false; + if (document.isAllowUpdate! && document.status == DocumentStatusEnum.rejected) { + val = false; + } + if (document.isAllowUpdate! && document.status == DocumentStatusEnum.needUpload) { + val = true; } - return isNetworkImage; + if (document.isAllowUpdate! && document.status == DocumentStatusEnum.review) { + val = true; + } + + return val; } - Widget buildCommentContainer({required DocumentData document}) { - String comment = ""; - if (document.status == 4 && document.comment != null) { - comment = document.comment ?? ""; - } +// List isLocalOrNetworkFiles({required ServiceVM model, required DocumentData document}) { +// bool isNetworkImage = false; +// print(document); +// if (!document.isLocalFile!) { +// isNetworkImage = document.documentUrl != null && document.documentUrl!.isNotEmpty ? true : false; +// } +// if (isNetworkImage) { +// return [ImageModel(id: document.id, isFromNetwork: isNetworkImage, filePath: document.documentUrl)]; +// } else { +// return [ImageModel(id: document.id, isFromNetwork: false, filePath: document.documentUrl)]; +// ; +// } +// } - if (comment.isEmpty) { - return const SizedBox(); - } - return Center(child: comment.toString().toText(color: MyColors.adCancelledStatusColor, fontSize: 14)).toContainer( - borderRadius: 8, - margin: const EdgeInsets.only(top: 10), - width: double.infinity, - backgroundColor: MyColors.adCancelledStatusColor.withOpacity(0.16), - ); +// bool isNeedToShow({required ServiceVM model, required DocumentData document}) { +// bool allow = false; +// bool isNetworkImage = document.documentUrl != null && document.documentUrl!.isNotEmpty && !(document.isLocalFile ?? true); +// if (isNetworkImage) { +// allow = true; +// } else { +// if (document.documentId == 1 && document.documentUrl!.isNotEmpty) { +// allow = true; +// } +// if (document.documentId == 2 && document.documentUrl!.isNotEmpty) { +// allow = true; +// } +// if (document.documentId == 3 && document.documentUrl!.isNotEmpty) { +// allow = true; +// } +// } +// return allow; +// } +// +// dynamic checkOnCrossPress({required ServiceVM model, required DocumentData document}) async { +// bool isNetworkImage = document.documentUrl != null && document.documentUrl!.isNotEmpty ? true : false; +// if (isNetworkImage) { +// print(document.documentUrl); +// return document.documentUrl; +// } + +//} else { +// if (document.documentId == 1) { +// model.commerceRemove; +// } +// if (document.documentId == 2) { +// model.commercialRemove; +// } +// if (document.documentId == 3) { +// model.vatRemove; +// } +// } +} + +bool isNetworkImage({required DocumentData document}) { + bool isNetworkImage = false; + if (!document.isLocalFile!) { + isNetworkImage = document.documentUrl != null && document.documentUrl!.isNotEmpty ? true : false; + } + return isNetworkImage; +} + +Widget buildCommentContainer({required DocumentData document}) { + String comment = ""; + if (document.status == 4 && document.comment != null) { + comment = document.comment ?? ""; } - Color getColorByStatus(int docStatus) { - switch (docStatus) { - case 1: - return MyColors.adPendingStatusColor; + if (comment.isEmpty) { + return const SizedBox(); + } + return Center(child: comment.toString().toText(color: MyColors.adCancelledStatusColor, fontSize: 14)).toContainer( + borderRadius: 8, + margin: const EdgeInsets.only(top: 10), + width: double.infinity, + backgroundColor: MyColors.adCancelledStatusColor.withOpacity(0.16), + ); +} - case 2: - return MyColors.adActiveStatusColor; +Color getColorByStatus(DocumentStatusEnum docStatus) { + switch (docStatus) { + case DocumentStatusEnum.pending: + return MyColors.adPendingStatusColor; - case 3: - return MyColors.greenColor; + case DocumentStatusEnum.approvedOrActive: + return MyColors.adActiveStatusColor; - case 4: - return MyColors.adCancelledStatusColor; + case DocumentStatusEnum.rejected: + return MyColors.adCancelledStatusColor; - default: - return MyColors.adPendingStatusColor; - } + case DocumentStatusEnum.needUpload: + return MyColors.adPendingStatusColor; + default: + return MyColors.adPendingStatusColor; } } diff --git a/lib/views/user/register_page.dart b/lib/views/user/register_page.dart index a5e9d20..feaa219 100644 --- a/lib/views/user/register_page.dart +++ b/lib/views/user/register_page.dart @@ -79,7 +79,6 @@ class _RegisterPageState extends State { DropdownField( dropdownValue: selectedDrop, (DropValue value) { - print("========"); selectedDrop = value; AppState().setUserRegisterCountrySelection = value; setState(() { diff --git a/lib/views/user/update_user_city_country.dart b/lib/views/user/update_user_city_country.dart index 5107c5c..f38f7bb 100644 --- a/lib/views/user/update_user_city_country.dart +++ b/lib/views/user/update_user_city_country.dart @@ -3,6 +3,7 @@ import 'package:mc_common_app/extensions/int_extensions.dart'; import 'package:mc_common_app/extensions/string_extensions.dart'; import 'package:mc_common_app/generated/locale_keys.g.dart'; import 'package:mc_common_app/models/general_models/widgets_models.dart'; +import 'package:mc_common_app/utils/utils.dart'; import 'package:mc_common_app/view_models/ad_view_model.dart'; import 'package:mc_common_app/view_models/user_view_model.dart'; import 'package:mc_common_app/widgets/common_widgets/app_bar.dart'; @@ -26,10 +27,19 @@ class _UpdateUserCityCountryState extends State { @override void initState() { + print(AppState().getUser!.data!.userInfo!.toJson()); context.read().getAllCountriesForUser(); super.initState(); } + @override + void dispose() { + city = null; + country = null; + print(" Dispose Called"); + super.dispose(); + } + @override Widget build(BuildContext context) { return Consumer(builder: (BuildContext context, UserVM uVM, Widget? child) { @@ -41,50 +51,56 @@ class _UpdateUserCityCountryState extends State { children: [ uVM.userCountries != null ? Container( - padding: const EdgeInsets.only(right: 20, left: 20, top: 12), - child: Builder(builder: (context) { - List userCountryDrop = []; - for (var element in uVM.userCountries!.data!) { - if (AppState().getUser.data!.userInfo!.countryId == element.id) { - country = DropValue(element.id?.toInt() ?? 0, element.countryName ?? "", ""); - } - userCountryDrop.add(DropValue(element.id?.toInt() ?? 0, element.countryName ?? "", "")); - } - return DropdownField( + padding: const EdgeInsets.only(right: 20, left: 20, top: 12), + child: Builder(builder: (context) { + List userCountryDrop = []; + for (var element in uVM.userCountries!.data!) { + var countryid = country == null ? AppState().getUser.data!.userInfo!.countryId : country!.id; + print("Country ID" + countryid.toString()); + if (countryid == element.id) { + print("Country Matched"); + country = DropValue(element.id?.toInt() ?? 0, element.countryName ?? "", ""); + } + userCountryDrop.add(DropValue(element.id?.toInt() ?? 0, element.countryName ?? "", "")); + } + return DropdownField( (DropValue value) async { - country = value; - await uVM.getAllCitiesForUser(country!.id); - setState(() {}); - }, - list: userCountryDrop, - dropdownValue: country != null && country != -1 ? DropValue(country!.id, country!.value, "") : null, - hint: country != null && country != -1 ? country!.value : "${LocaleKeys.country.tr()} *", - // errorValue: adVM.vehicleCountryId.errorValue, - ); - })) + country = value; + city = null; + await uVM.getAllCitiesForUser(country!.id); + setState(() {}); + }, + list: userCountryDrop, + dropdownValue: country != null && country != -1 ? DropValue(country!.id, country!.value, "") : null, + hint: country != null && country != -1 ? country!.value : "${LocaleKeys.country.tr()} *", + // errorValue: adVM.vehicleCountryId.errorValue, + ); + })) : SizedBox(), - uVM.userCities != null + uVM.userCities != null && uVM.userCities!.data!.isNotEmpty ? Container( - padding: const EdgeInsets.only(right: 20, left: 20, top: 12), - child: Builder(builder: (context) { - List userCityDrop = []; - for (var element in uVM.userCities!.data!) { - if (AppState().getUser.data!.userInfo!.cityId == element.id) { - city = DropValue(element.id?.toInt() ?? 0, element.cityName ?? "", ""); - } - userCityDrop.add(DropValue(element.id?.toInt() ?? 0, element.cityName ?? "", "")); - } - return DropdownField( + padding: const EdgeInsets.only(right: 20, left: 20, top: 12), + child: Builder(builder: (context) { + List userCityDrop = []; + for (var element in uVM.userCities!.data!) { + var cid = city == null ? AppState().getUser.data!.userInfo!.cityId : city!.id; + print("City ID" + cid.toString()); + if (cid == element.id) { + city = DropValue(element.id?.toInt() ?? 0, element.cityName ?? "", ""); + } + userCityDrop.add(DropValue(element.id?.toInt() ?? 0, element.cityName ?? "", "")); + } + return DropdownField( (DropValue value) { - city = value; - setState(() {}); - }, - list: userCityDrop, - dropdownValue: city != null && city != -1 ? DropValue(city!.id, city!.value, "") : null, - hint: city != null && city != -1 ? city!.value : "${LocaleKeys.city.tr()} *", - // errorValue: adVM.vehicleCountryId.errorValue, - ); - })) + city = value; + setState(() {}); + }, + list: userCityDrop, + dropdownValue: city != null && city!.id != -1 ? DropValue(city!.id, city!.value, "") : null, + hint: city != null && city != -1 ? city!.value : "${LocaleKeys.city.tr()} *", + // errorValue: uVM.userCities!.data!.isEmpty ? "No Cities Found" : "", + ); + })) : SizedBox(), 20.height, Padding( @@ -93,7 +109,9 @@ class _UpdateUserCityCountryState extends State { title: LocaleKeys.confirm.tr(), maxWidth: double.infinity, onPressed: () async { - await uVM.userDetailsUpdate(context, AppState().getUser.data!.userInfo!.firstName!, AppState().getUser.data!.userInfo!.lastName!, city != null ? city?.id.toString() : null); + + await uVM.userDetailsUpdate( + context, AppState().getUser.data!.userInfo!.firstName!, AppState().getUser.data!.userInfo!.lastName!, city != null ? city?.id.toString() : null, city!.value, country!.value); }, ), ), diff --git a/lib/views/user/update_user_details.dart b/lib/views/user/update_user_details.dart index 4731bd2..1a51d29 100644 --- a/lib/views/user/update_user_details.dart +++ b/lib/views/user/update_user_details.dart @@ -1,3 +1,4 @@ +import 'package:mc_common_app/classes/app_state.dart'; import 'package:mc_common_app/extensions/int_extensions.dart'; import 'package:mc_common_app/extensions/string_extensions.dart'; import 'package:mc_common_app/generated/locale_keys.g.dart'; @@ -55,8 +56,7 @@ class _UpdateUserDetailsState extends State { title: LocaleKeys.confirm.tr(), maxWidth: double.infinity, onPressed: () async { - await userVM.userDetailsUpdate(context, firstname, lastname, null); - + await userVM.userDetailsUpdate(context, firstname, lastname, AppState().getUser.data!.userInfo!.cityId!.toString(), null, null); }, ), ],