From 3ce3d2b1db4de89315f0cfe31500f2caa02939fe Mon Sep 17 00:00:00 2001 From: Faiz Hashmi Date: Thu, 22 Aug 2024 14:33:07 +0300 Subject: [PATCH] Fixes few things --- lib/api/api_client.dart | 2 +- lib/classes/consts.dart | 52 ++++----- .../advertisment_models/ad_details_model.dart | 3 + .../provider_profile_model.dart | 7 +- lib/repositories/appointment_repo.dart | 37 +++--- lib/repositories/branch_repo.dart | 90 ++++++++++----- lib/repositories/subscription_repo.dart | 4 +- lib/repositories/user_repo.dart | 8 +- lib/view_models/ad_view_model.dart | 1 + lib/view_models/appointments_view_model.dart | 106 +++++++++++------- .../components/ads_list_widget.dart | 5 +- lib/views/appointments/pick_items_view.dart | 25 ++--- .../common_widgets/provider_details_card.dart | 40 ++++--- 13 files changed, 211 insertions(+), 169 deletions(-) diff --git a/lib/api/api_client.dart b/lib/api/api_client.dart index ebb9831..ceafccf 100644 --- a/lib/api/api_client.dart +++ b/lib/api/api_client.dart @@ -303,7 +303,7 @@ class ApiClientImp implements ApiClient { Future refreshTokenAPI(String token, String refreshToken) async { var postParams = {"token": token, "refreshToken": refreshToken}; // String t = AppState().getUser.data!.accessToken ?? ""; - return await postJsonForObject((json) => RefreshToken.fromJson(json), ApiConsts.RefreshToken, postParams); + return await postJsonForObject((json) => RefreshToken.fromJson(json), ApiConsts.refreshToken, postParams); } Future updateUserToken() async { diff --git a/lib/classes/consts.dart b/lib/classes/consts.dart index 41577b2..34d26ba 100644 --- a/lib/classes/consts.dart +++ b/lib/classes/consts.dart @@ -1,15 +1,14 @@ -import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/cupertino.dart'; import 'package:mc_common_app/generated/codegen_loader.g.dart'; class ApiConsts { // static String baseUrl = "http://10.200.204.20:2801/"; // Local server static String baseUrl = "https://ms.hmg.com/"; // production server - static String baseUrlServices = "$baseUrl"; // production server - static String BasicOTP = "${baseUrlServices}api/Register/BasicOTP"; - static String BasicVerify = "${baseUrlServices}api/Register/BasicVerify"; - static String BasicComplete = "${baseUrlServices}api/Register/BasicComplete"; - static String RefreshToken = "${baseUrlServices}api/Account/RefreshToken"; + static String baseUrlServices = baseUrl; // production server + static String basicOTP = "${baseUrlServices}api/Register/BasicOTP"; + static String basicVerify = "${baseUrlServices}api/Register/BasicVerify"; + static String basicComplete = "${baseUrlServices}api/Register/BasicComplete"; + static String refreshToken = "${baseUrlServices}api/Account/RefreshToken"; //User static String Login_V1 = "${baseUrlServices}api/Account/Login_V1"; @@ -36,38 +35,40 @@ class ApiConsts { static String GetUserImage = "${baseUrlServices}api/ProfileImage"; //Profile - static String GetProviderDocument = "${baseUrlServices}api/ServiceProviders/ServiceProviderDocument_Get"; - static String ServiceProviderDocument_Update = "${baseUrlServices}api/ServiceProviders/ServiceProviderDocument_Update"; + static String fetProviderDocument = "${baseUrlServices}api/ServiceProviders/ServiceProviderDocument_Get"; + static String serviceProviderDocumentUpdate = "${baseUrlServices}api/ServiceProviders/ServiceProviderDocument_Update"; //Branch static String getProviderBranch = "${baseUrlServices}api/ServiceProviders/ServiceProviderBranch_Get"; static String createProviderBranch = "${baseUrlServices}api/ServiceProviders/ServiceProviderBranch_Create"; static String updateProviderBranch = "${baseUrlServices}api/ServiceProviders/ServiceProviderBranch_Update"; - static String ServiceProviderBranchGet = "${baseUrlServices}api/ServiceProviders/ServiceProviderBranch_Get"; - static String ServiceCategory_Get = "${baseUrlServices}api/Master/ServiceCategory_Get"; - static String Services_Get = "${baseUrlServices}api/ServiceProviders/Services_Get"; - static String ServiceProviderService_Create = "${baseUrlServices}api/ServiceProviders/ServiceProviderService_Create"; - static String ServiceProviderService_Update = "${baseUrlServices}api/ServiceProviders/ServiceProviderService_Update"; - static String GetProviderServices = "${baseUrlServices}api/ServiceProviders/ServiceProviderService_Get"; + static String serviceProviderBranchGet = "${baseUrlServices}api/ServiceProviders/ServiceProviderBranch_Get"; + static String serviceCategoryGet = "${baseUrlServices}api/Master/ServiceCategory_Get"; + static String servicesGet = "${baseUrlServices}api/ServiceProviders/Services_Get"; + static String serviceProviderServiceCreate = "${baseUrlServices}api/ServiceProviders/ServiceProviderService_Create"; + static String serviceProviderServiceUpdate = "${baseUrlServices}api/ServiceProviders/ServiceProviderService_Update"; + static String getProviderServices = "${baseUrlServices}api/ServiceProviders/ServiceProviderService_Get"; static String setScheduleInactive = "${baseUrlServices}api/ServiceProviders/BranchAppointmentSchedule_IsActiveUpdate"; - static String ServiceProviderService_Get = "${baseUrlServices}api/ServiceProviders/ServiceProviderService_Get"; - static String BranchesAndServices = "${baseUrlServices}api/ServiceProviders/ServiceProviderDetail_Get"; + static String serviceProviderServiceGet = "${baseUrlServices}api/ServiceProviders/ServiceProviderService_Get"; + static String branchesAndServices = "${baseUrlServices}api/ServiceProviders/ServiceProviderDetail_Get"; static String serviceProviderDDLGet = "${baseUrlServices}api/ServiceProviders/ServiceProviderDDL_Get"; - static String GetAllNearBranches = "${baseUrlServices}api/ServiceProviders/ServiceProviderBranchDetail_Get"; + static String getAllNearBranches = "${baseUrlServices}api/ServiceProviders/ServiceProviderBranchDetail_Get"; static String getMyRecentBranches = "${baseUrlServices}api/ServiceProviders/ServiceProviderBranchRecent_Get"; static String getBranchRatings = "${baseUrlServices}api/ServiceProviders/BranchRating_Get"; static String createBranchRatings = "${baseUrlServices}api/ServiceProviders/BranchRating_Create"; + static String favouriteServiceProviderCreate = "${baseUrlServices}api/ServiceProviders/FavouriteServiceProvider_Create"; + static String unFavouriteServiceProvider = "${baseUrlServices}api/ServiceProviders/UnFavouriteServiceProvider"; + static String favouriteServiceProviderGet = "${baseUrlServices}api/ServiceProviders/FavouriteServiceProvider_Get"; //Appointment APIs static String serviceProvidersAppointmentGet = "${baseUrlServices}api/ServiceProviders/ServiceProvidersAppointment_Get"; static String customersAppointmentGetByFilters = "${baseUrlServices}api/ServiceProviders/ServiceProvidersAppointmentSearchFiltersByCustomer_Get"; - static String serviceCategoryGet = "${baseUrlServices}api/Master/ServiceCategory_Get"; static String serviceItemsGet = "${baseUrlServices}api/ServiceProviders/ServiceItem_Get"; - static String GetServiceItemAppointmentScheduleSlots = "${baseUrlServices}api/ServiceProviders/ServiceItemAppointmentScheduleSlots_GetByAppointmentType"; - static String ServiceProvidersAppointmentCreate = "${baseUrlServices}api/ServiceProviders/ServiceProvidersAppointmentList_Create"; - static String ServiceProviderAppointmentRescheduleCancelAppointment = "${baseUrlServices}api/ServiceProviders/ServiceProviderAppointment_RescheduleCancelAppointment"; - static String AddNewServicesInAppointment = "${baseUrlServices}api/ServiceProviders/ServiceProviderAppointment_ServiceItemAdd"; + static String getServiceItemAppointmentScheduleSlots = "${baseUrlServices}api/ServiceProviders/ServiceItemAppointmentScheduleSlots_GetByAppointmentType"; + static String serviceProvidersAppointmentCreate = "${baseUrlServices}api/ServiceProviders/ServiceProvidersAppointmentList_Create"; + static String serviceProviderAppointmentRescheduleCancelAppointment = "${baseUrlServices}api/ServiceProviders/ServiceProviderAppointment_RescheduleCancelAppointment"; + static String addNewServicesInAppointment = "${baseUrlServices}api/ServiceProviders/ServiceProviderAppointment_ServiceItemAdd"; static String getAppointmentSlots = "${baseUrlServices}api/ServiceProviders/ScheduleSlotsInfo_Get"; static String updateAppointmentStatus = "${baseUrlServices}api/ServiceProviders/ServiceProvidersAppointmentStatus_Update"; @@ -127,8 +128,8 @@ class ApiConsts { static String getAllSubscriptions = "${baseUrlServices}api/Common/Subscription_Get"; static String getSubscriptionBySP = "${baseUrlServices}api/Common/SubscriptionBySP_Get"; static String calculationUpgradePrice = "${baseUrlServices}api/ServiceProviders/CalculationUpgradePrice"; - static String payFortOrder_ProviderSubscription_Create = "${baseUrlServices}api/Payment/PayFortOrder_ProviderSubscription_Create"; - static String getSPBranchUser_Get = "${baseUrlServices}api/ServiceProviders/SPBranchUser_Get"; + static String payFortOrderProviderSubscriptionCreate = "${baseUrlServices}api/Payment/PayFortOrder_ProviderSubscription_Create"; + static String getSPBranchUserGet = "${baseUrlServices}api/ServiceProviders/SPBranchUser_Get"; // Payment static String paymentWebViewUrl = "https://ms.hmg.com/pay/PaymentHome"; @@ -191,8 +192,7 @@ class GlobalConsts { static String adDurationPhoneNumberError = "Phone number cannot be empty"; static String adReservablePriceErrorConst = "Ad Reservable price cannot be empty"; static String homeLocationEmptyError = "Home location cannot be empty"; - static String reserveAdPriceInfo = - "Some dummy description to explain the following concept. This price will be for 24 hours and if a user cancels the reservations before 24 hours then the amount will be automatically refunded to the buyer."; + static String reserveAdPriceInfo = "Some dummy description to explain the following concept. This price will be for 24 hours and if a user cancels the reservations before 24 hours then the amount will be automatically refunded to the buyer."; } class MyAssets { diff --git a/lib/models/advertisment_models/ad_details_model.dart b/lib/models/advertisment_models/ad_details_model.dart index c9f785e..4ec8bf3 100644 --- a/lib/models/advertisment_models/ad_details_model.dart +++ b/lib/models/advertisment_models/ad_details_model.dart @@ -45,6 +45,7 @@ class AdDetailsModel { String? phoneNo; String? whatsAppNo; String? adOwnerName; + String? warrantyYears; CreatedByRoleEnum? createdByRoleEnum; List? adMessages; @@ -86,6 +87,7 @@ class AdDetailsModel { this.phoneNo, this.whatsAppNo, this.adOwnerName, + this.warrantyYears, this.createdByRoleEnum, this.modifiedOn, this.adMessages, @@ -136,6 +138,7 @@ class AdDetailsModel { phoneNo = json['phoneNo']; whatsAppNo = json['whatsAppNo']; adOwnerName = json['adOwnerName'] ?? ""; + warrantyYears = json['warantyYears'] ?? ""; adPostStatus = (json['statusID'] as int).toAdPostEnum(); adReserveStatus = AdReserveStatus.defaultStatus; createdByRoleEnum = (json['createdByRole'] as int).toCreatedByRoleEnum(); diff --git a/lib/models/provider_branches_models/provider_profile_model.dart b/lib/models/provider_branches_models/provider_profile_model.dart index f32879d..cbcefae 100644 --- a/lib/models/provider_branches_models/provider_profile_model.dart +++ b/lib/models/provider_branches_models/provider_profile_model.dart @@ -21,12 +21,11 @@ class ProviderProfileModel { final String? companyDescription; final int? allDocStatus; final bool? isValidSubscription; - final bool? isFavorite; + bool? isFavorite; final String? userId; final List? serviceProviderBranch; - factory ProviderProfileModel.fromJson(Map json) => - ProviderProfileModel( + factory ProviderProfileModel.fromJson(Map json) => ProviderProfileModel( id: json["id"], companyName: json["companyName"], countryName: json["countryName"], @@ -35,7 +34,7 @@ class ProviderProfileModel { allDocStatus: json["allDocStatus"], isValidSubscription: json["isValidSubscription"], userId: json["userID"], - isFavorite: json["isFavorite"] ?? false, + isFavorite: json["isFavourite"] ?? false, serviceProviderBranch: json["serviceProviderBranch"] == null ? null : List.from(json["serviceProviderBranch"].map((x) => BranchDetailModel.fromJson(x))), ); } diff --git a/lib/repositories/appointment_repo.dart b/lib/repositories/appointment_repo.dart index bbc36f2..649860d 100644 --- a/lib/repositories/appointment_repo.dart +++ b/lib/repositories/appointment_repo.dart @@ -50,7 +50,7 @@ abstract class AppointmentRepo { Future cancelOrRescheduleServiceAppointment({required int serviceAppointmentID, required int serviceSlotID, required int appointmentScheduleAction}); - Future addProviderToFavourite({required int providerID}); + } class AppointmentRepoImp implements AppointmentRepo { @@ -120,42 +120,42 @@ class AppointmentRepoImp implements AppointmentRepo { ]; GenericRespModel adsGenericModel = await apiClient.postJsonForObject( (json) => GenericRespModel.fromJson(json), - ApiConsts.GetServiceItemAppointmentScheduleSlots, + ApiConsts.getServiceItemAppointmentScheduleSlots, queryParameters, token: t, ); if (adsGenericModel.data == null) { return []; } - List serviceAppointmentScheduleModel = - List.generate(adsGenericModel.data.length, (index) => ServiceAppointmentScheduleModel.fromJson(adsGenericModel.data[index], isForAppointment: true)); + List serviceAppointmentScheduleModel = List.generate(adsGenericModel.data.length, (index) => ServiceAppointmentScheduleModel.fromJson(adsGenericModel.data[index], isForAppointment: true)); return serviceAppointmentScheduleModel; } + @override Future createServiceAppointment({required List schedules, required int serviceProviderID}) async { String t = appState.getUser.data!.accessToken ?? ""; int customerId = appState.getUser.data!.userInfo!.customerId ?? 0; List> mapList = []; - schedules.forEach((schedule) { + for (var schedule in schedules) { List serviceItemIds = []; - schedule.servicesListInAppointment!.forEach((service) { - service.serviceItems!.forEach((item) { + for (var service in schedule.servicesListInAppointment!) { + for (var item in service.serviceItems!) { serviceItemIds.add(item.id!); - }); - }); + } + } mapList.add({ "serviceSlotID": schedule.selectedCustomTimeDateSlotModel!.date!.slotId, "serviceProviderID": serviceProviderID, "customerID": customerId, "serviceItemID": serviceItemIds, }); - }); + } log("maplist: ${mapList.toString()}"); GenericRespModel adsGenericModel = await apiClient.postJsonForObject( (json) => GenericRespModel.fromJson(json), - ApiConsts.ServiceProvidersAppointmentCreate, + ApiConsts.serviceProvidersAppointmentCreate, mapList, token: t, ); @@ -175,7 +175,7 @@ class AppointmentRepoImp implements AppointmentRepo { GenericRespModel adsGenericModel = await apiClient.postJsonForObject( (json) => GenericRespModel.fromJson(json), - ApiConsts.ServiceProviderAppointmentRescheduleCancelAppointment, + ApiConsts.serviceProviderAppointmentRescheduleCancelAppointment, payload, token: t, ); @@ -253,16 +253,5 @@ class AppointmentRepoImp implements AppointmentRepo { return await apiClient.postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.createMergeAppointment, map, token: t); } - @override - Future addProviderToFavourite({required int providerID}) async { - final customerID = appState.getUser.data!.userInfo!.customerId; - final parameters = {"providerID": providerID, "customerID": customerID}; - GenericRespModel adsGenericModel = await apiClient.postJsonForObject( - (json) => GenericRespModel.fromJson(json), - ApiConsts.createBranchRatings, - parameters, - token: appState.getUser.data!.accessToken, - ); - return adsGenericModel; - } + } diff --git a/lib/repositories/branch_repo.dart b/lib/repositories/branch_repo.dart index 01f5862..4db4ced 100644 --- a/lib/repositories/branch_repo.dart +++ b/lib/repositories/branch_repo.dart @@ -80,6 +80,12 @@ abstract class BranchRepo { Future> getBranchRatings({required int serviceProviderBranchID}); Future submitBranchRatings({required int serviceProviderBranchID, required String title, required String review, required double ratingNo}); + + Future addProviderToFavourite({required int providerID}); + + Future removeProviderFromFavourite({required int providerID}); + + Future> getMyFavoriteProviders(); } class BranchRepoImp implements BranchRepo { @@ -106,27 +112,27 @@ class BranchRepoImp implements BranchRepo { Future fetchAllBranches() async { var postParams = {"ServiceProviderID": AppState().getUser.data?.userInfo?.providerId.toString() ?? ""}; String t = AppState().getUser.data!.accessToken ?? ""; - return await apiClient.getJsonForObject((json) => Branch.fromJson(json), ApiConsts.ServiceProviderBranchGet, queryParameters: postParams, token: t); + return await apiClient.getJsonForObject((json) => Branch.fromJson(json), ApiConsts.serviceProviderBranchGet, queryParameters: postParams, token: t); } @override Future fetchBranchCategory() async { var postParams = {"ServiceProviderID": AppState().getUser.data?.userInfo?.providerId.toString() ?? ""}; String t = AppState().getUser.data!.accessToken ?? ""; - return await apiClient.getJsonForObject((json) => Category.fromJson(json), ApiConsts.ServiceCategory_Get, queryParameters: postParams, token: t); + return await apiClient.getJsonForObject((json) => Category.fromJson(json), ApiConsts.serviceCategoryGet, queryParameters: postParams, token: t); } @override Future fetchServicesByCategoryId({required int serviceCategoryId}) async { var postParams = {"ServiceCategoryID": serviceCategoryId.toString()}; String t = AppState().getUser.data!.accessToken ?? ""; - return await apiClient.getJsonForObject((json) => Services.fromJson(json), ApiConsts.Services_Get, queryParameters: serviceCategoryId.toString() != "-1" ? postParams : null, token: t); + return await apiClient.getJsonForObject((json) => Services.fromJson(json), ApiConsts.servicesGet, queryParameters: serviceCategoryId.toString() != "-1" ? postParams : null, token: t); } @override Future createNewService(List> map) async { String t = AppState().getUser.data!.accessToken ?? ""; - return await apiClient.postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.ServiceProviderService_Create, map, token: t); + return await apiClient.postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.serviceProviderServiceCreate, map, token: t); } @override @@ -136,9 +142,7 @@ class BranchRepoImp implements BranchRepo { }; String? token = AppState().getUser.data?.accessToken; debugPrint(token); - return await injector - .get() - .getJsonForObject((json) => Document.fromJson(json), ApiConsts.GetProviderDocument, queryParameters: queryParameters, token: AppState().getUser.data!.accessToken ?? ""); + return await injector.get().getJsonForObject((json) => Document.fromJson(json), ApiConsts.fetProviderDocument, queryParameters: queryParameters, token: AppState().getUser.data!.accessToken ?? ""); } @override @@ -146,26 +150,19 @@ class BranchRepoImp implements BranchRepo { List> map = []; for (int i = 0; i < documents!.length; i++) { if (documents[i].document != null) { - var postParams = { - "id": documents[i].id, - "serviceProviderID": documents[i].serviceProviderId, - "documentID": documents[i].documentId, - "documentExt": documents[i].fileExt, - "documentImage": documents[i].document, - "isActive": true - }; + var postParams = {"id": documents[i].id, "serviceProviderID": documents[i].serviceProviderId, "documentID": documents[i].documentId, "documentExt": documents[i].fileExt, "documentImage": documents[i].document, "isActive": true}; map.add(postParams); } } String t = AppState().getUser.data!.accessToken ?? ""; - return await apiClient.postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.ServiceProviderDocument_Update, map, token: t); + return await apiClient.postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.serviceProviderDocumentUpdate, map, token: t); } @override Future getBranchAndServices() async { var postParams = {"serviceProviderID": AppState().getUser.data?.userInfo?.providerId.toString() ?? ""}; String t = AppState().getUser.data!.accessToken ?? ""; - return await apiClient.getJsonForObject((json) => ProviderModel.fromJson(json), ApiConsts.BranchesAndServices, queryParameters: postParams, token: t); + return await apiClient.getJsonForObject((json) => ProviderModel.fromJson(json), ApiConsts.branchesAndServices, queryParameters: postParams, token: t); } @override @@ -206,13 +203,13 @@ class BranchRepoImp implements BranchRepo { @override Future createService(List> map) async { String t = AppState().getUser.data!.accessToken ?? ""; - return await apiClient.postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.ServiceProviderService_Create, map, token: t); + return await apiClient.postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.serviceProviderServiceCreate, map, token: t); } @override Future updateService(List> map) async { String t = AppState().getUser.data!.accessToken ?? ""; - return await apiClient.postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.ServiceProviderService_Update, map, token: t); + return await apiClient.postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.serviceProviderServiceUpdate, map, token: t); } @override @@ -264,18 +261,18 @@ class BranchRepoImp implements BranchRepo { }; String t = AppState().getUser.data!.accessToken ?? ""; debugPrint("token " + t); - return await apiClient.getJsonForObject((json) => Services.fromJson(json), ApiConsts.GetProviderServices, queryParameters: postParams, token: t); + return await apiClient.getJsonForObject((json) => Services.fromJson(json), ApiConsts.getProviderServices, queryParameters: postParams, token: t); } @override Future addNewServicesInAppointment(Map map) async { String t = AppState().getUser.data!.accessToken ?? ""; - return await apiClient.postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.AddNewServicesInAppointment, map, token: t); + return await apiClient.postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.addNewServicesInAppointment, map, token: t); } @override Future> getAllNearBranchAndServices() async { - GenericRespModel adsGenericModel = await apiClient.getJsonForObject((json) => GenericRespModel.fromJson(json), ApiConsts.GetAllNearBranches, token: appState.getUser.data!.accessToken); + GenericRespModel adsGenericModel = await apiClient.getJsonForObject((json) => GenericRespModel.fromJson(json), ApiConsts.getAllNearBranches, token: appState.getUser.data!.accessToken); List nearBranches = List.generate(adsGenericModel.data.length, (index) => BranchDetailModel.fromJson(adsGenericModel.data[index])); return nearBranches; } @@ -306,8 +303,7 @@ class BranchRepoImp implements BranchRepo { @override Future getBranchAndServicesByProviderId(int providerId) async { var postParams = {"serviceProviderID": providerId.toString()}; - GenericRespModel adsGenericModel = - await apiClient.getJsonForObject((json) => GenericRespModel.fromJson(json), ApiConsts.BranchesAndServices, token: appState.getUser.data!.accessToken, queryParameters: postParams); + GenericRespModel adsGenericModel = await apiClient.getJsonForObject((json) => GenericRespModel.fromJson(json), ApiConsts.branchesAndServices, token: appState.getUser.data!.accessToken, queryParameters: postParams); return ProviderProfileModel.fromJson(adsGenericModel.data); } @@ -352,7 +348,7 @@ class BranchRepoImp implements BranchRepo { GenericRespModel adsGenericModel = await apiClient.getJsonForObject( (json) => GenericRespModel.fromJson(json), - ApiConsts.GetAllNearBranches, + ApiConsts.getAllNearBranches, token: appState.getUser.data!.accessToken, queryParameters: postParams, ); @@ -386,4 +382,48 @@ class BranchRepoImp implements BranchRepo { ); return adsGenericModel; } + + @override + Future addProviderToFavourite({required int providerID}) async { + final customerID = appState.getUser.data!.userInfo!.customerId; + final parameters = { + "providerID": providerID.toString(), + "customerID": customerID.toString(), + }; + GenericRespModel adsGenericModel = await apiClient.postJsonForObject( + (json) => GenericRespModel.fromJson(json), + ApiConsts.favouriteServiceProviderCreate, + parameters, + token: appState.getUser.data!.accessToken, + ); + return adsGenericModel; + } + + @override + Future removeProviderFromFavourite({required int providerID}) async { + final parameters = {"id": providerID.toString()}; + GenericRespModel adsGenericModel = await apiClient.postJsonForObject( + (json) => GenericRespModel.fromJson(json), + ApiConsts.unFavouriteServiceProvider, + parameters, + token: appState.getUser.data!.accessToken, + ); + return adsGenericModel; + } + + @override + Future> getMyFavoriteProviders() async { + final customerID = appState.getUser.data!.userInfo!.customerId; + + var postParams = {"customerID": customerID.toString()}; + + GenericRespModel adsGenericModel = await apiClient.getJsonForObject( + (json) => GenericRespModel.fromJson(json), + ApiConsts.favouriteServiceProviderGet, + token: appState.getUser.data!.accessToken, + queryParameters: postParams, + ); + List nearBranches = List.generate(adsGenericModel.data.length, (index) => BranchDetailModel.fromJson(adsGenericModel.data[index])); + return nearBranches; + } } diff --git a/lib/repositories/subscription_repo.dart b/lib/repositories/subscription_repo.dart index 606d2a1..ad2e154 100644 --- a/lib/repositories/subscription_repo.dart +++ b/lib/repositories/subscription_repo.dart @@ -87,7 +87,7 @@ class SubscriptionRepoImp extends SubscriptionRepo { return await injector.get().postJsonForObject( (json) => MResponse.fromJson(json), - ApiConsts.payFortOrder_ProviderSubscription_Create, + ApiConsts.payFortOrderProviderSubscriptionCreate, map, token: t, ); @@ -99,7 +99,7 @@ class SubscriptionRepoImp extends SubscriptionRepo { GenericRespModel genericRespModel = await injector.get().getJsonForObject( (json) => GenericRespModel.fromJson(json), - ApiConsts.getSPBranchUser_Get, + ApiConsts.getSPBranchUserGet, token: t, queryParameters: map, ); diff --git a/lib/repositories/user_repo.dart b/lib/repositories/user_repo.dart index 75a7500..dc499d0 100644 --- a/lib/repositories/user_repo.dart +++ b/lib/repositories/user_repo.dart @@ -85,7 +85,7 @@ class UserRepoImp implements UserRepo { t = AppState().getUser.data!.accessToken ?? ""; debugPrint("token $t"); } - return await injector.get().postJsonForObject((json) => BasicOtpRespModel.fromJson(json), ApiConsts.BasicOTP, postParams, token: t); + return await injector.get().postJsonForObject((json) => BasicOtpRespModel.fromJson(json), ApiConsts.basicOTP, postParams, token: t); } @override @@ -100,7 +100,7 @@ class UserRepoImp implements UserRepo { t = AppState().getUser.data!.accessToken ?? ""; debugPrint("token $t"); } - return await injector.get().postJsonForObject((json) => RegisterUserRespModel.fromJson(json), ApiConsts.BasicVerify, postParams, token: t); + return await injector.get().postJsonForObject((json) => RegisterUserRespModel.fromJson(json), ApiConsts.basicVerify, postParams, token: t); } @override @@ -116,7 +116,7 @@ class UserRepoImp implements UserRepo { t = AppState().getUser.data!.accessToken ?? ""; debugPrint("token $t"); } - return await injector.get().postJsonForObject((json) => RegisterUserRespModel.fromJson(json), ApiConsts.BasicComplete, postParams, token: t); + return await injector.get().postJsonForObject((json) => RegisterUserRespModel.fromJson(json), ApiConsts.basicComplete, postParams, token: t); } @override @@ -156,7 +156,7 @@ class UserRepoImp implements UserRepo { Future refreshTokenAPI(String token, String refreshToken) async { var postParams = {"token": token, "refreshToken": refreshToken}; // String t = AppState().getUser.data!.accessToken ?? ""; - return await injector.get().postJsonForObject((json) => RefreshToken.fromJson(json), ApiConsts.RefreshToken, postParams); + return await injector.get().postJsonForObject((json) => RefreshToken.fromJson(json), ApiConsts.refreshToken, postParams); } @override diff --git a/lib/view_models/ad_view_model.dart b/lib/view_models/ad_view_model.dart index 9e0ae74..beafaee 100644 --- a/lib/view_models/ad_view_model.dart +++ b/lib/view_models/ad_view_model.dart @@ -1814,6 +1814,7 @@ class AdVM extends BaseVM { } isNumberOnWhatsApp = previousAdDetails!.whatsAppNo != null; + warrantyDuration = previousAdDetails!.warrantyYears ?? ""; notifyListeners(); } diff --git a/lib/view_models/appointments_view_model.dart b/lib/view_models/appointments_view_model.dart index ea8166b..2145351 100644 --- a/lib/view_models/appointments_view_model.dart +++ b/lib/view_models/appointments_view_model.dart @@ -1,5 +1,6 @@ import 'dart:developer'; +import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:mc_common_app/classes/consts.dart'; import 'package:mc_common_app/config/routes.dart'; @@ -129,7 +130,7 @@ class AppointmentsVM extends BaseVM { if (genericRespModel.data.isEmpty) { Utils.hideLoading(context); - Utils.showToast("${genericRespModel.message.toString()}"); + Utils.showToast(genericRespModel.message.toString()); return; } @@ -182,20 +183,20 @@ class AppointmentsVM extends BaseVM { if (genericRespModel.messageStatus == 2 || genericRespModel.data == null) { Utils.hideLoading(context); - Utils.showToast("${genericRespModel.message.toString()}"); + Utils.showToast(genericRespModel.message.toString()); return; } if (genericRespModel.messageStatus == 1) { context.read().onNavbarTapped(1); applyFilterOnAppointmentsVM(appointmentStatusEnum: AppointmentStatusEnum.cancelled); - Utils.showToast("${genericRespModel.message.toString()}"); + Utils.showToast(genericRespModel.message.toString()); await getMyAppointments(); Utils.hideLoading(context); getMyAppointments(); navigateReplaceWithNameUntilRoute(context, AppRoutes.dashboard); } } catch (e) { - Utils.showToast("${e.toString()}"); + Utils.showToast(e.toString()); } } @@ -239,9 +240,7 @@ class AppointmentsVM extends BaseVM { } void removeServiceInCurrentAppointment(int index) { - int serviceId = servicesInCurrentAppointment - .elementAt(index) - .serviceProviderServiceId ?? -1; + int serviceId = servicesInCurrentAppointment.elementAt(index).serviceProviderServiceId ?? -1; allSelectedItemsInAppointments.removeWhere((element) => element.serviceProviderServiceId == serviceId); servicesInCurrentAppointment.removeAt(index); notifyListeners(); @@ -362,8 +361,7 @@ class AppointmentsVM extends BaseVM { myAppointments = await appointmentRepo.getMyAppointmentsForCustomersByFilters(); // myFilteredAppointments = myAppointments; - myUpComingAppointments = - myAppointments.where((element) => element.appointmentStatusEnum == AppointmentStatusEnum.booked || element.appointmentStatusEnum == AppointmentStatusEnum.confirmed).toList(); + myUpComingAppointments = myAppointments.where((element) => element.appointmentStatusEnum == AppointmentStatusEnum.booked || element.appointmentStatusEnum == AppointmentStatusEnum.confirmed).toList(); setState(ViewState.idle); applyFilterOnAppointmentsVM(appointmentStatusEnum: AppointmentStatusEnum.allAppointments); notifyListeners(); @@ -434,8 +432,7 @@ class AppointmentsVM extends BaseVM { bool inNeedToEnableMergeButton = false; updateCheckBoxInMergeRequest(int currentIndex) { - myFilteredAppointments2[selectedAppointmentIndex].customerAppointmentList![currentIndex].isSelected = - !(myFilteredAppointments2[selectedAppointmentIndex].customerAppointmentList?[currentIndex].isSelected ?? false); + myFilteredAppointments2[selectedAppointmentIndex].customerAppointmentList![currentIndex].isSelected = !(myFilteredAppointments2[selectedAppointmentIndex].customerAppointmentList?[currentIndex].isSelected ?? false); int count = countSelected(myFilteredAppointments2[selectedAppointmentIndex].customerAppointmentList ?? []); if (count > 1) @@ -446,10 +443,7 @@ class AppointmentsVM extends BaseVM { } int countSelected(List appointments) { - return appointments - .where((appointment) => appointment.isSelected == true) - .toList() - .length; + return appointments.where((appointment) => appointment.isSelected == true).toList().length; } updateSelectedAppointmentDate({required int dateIndex, required int scheduleIndex}) { @@ -507,8 +501,7 @@ class AppointmentsVM extends BaseVM { for (var element in allSelectedItemsInAppointments) { if (!ifItemAlreadySelected(element.id!)) { servicesInCurrentAppointment[serviceIndex].serviceItems!.add(serviceItemsFromApi[index]); - servicesInCurrentAppointment[serviceIndex].currentTotalServicePrice = - servicesInCurrentAppointment[serviceIndex].currentTotalServicePrice + double.parse((serviceItemsFromApi[index].price) ?? "0.0"); + servicesInCurrentAppointment[serviceIndex].currentTotalServicePrice = servicesInCurrentAppointment[serviceIndex].currentTotalServicePrice + double.parse((serviceItemsFromApi[index].price) ?? "0.0"); } } } @@ -516,8 +509,7 @@ class AppointmentsVM extends BaseVM { selectedSubServicesCounter = selectedSubServicesCounter - 1; currentServiceSelection!.serviceItems!.removeWhere((element) => element.id == itemId); allSelectedItemsInAppointments.removeWhere((element) => element.id == itemId); - servicesInCurrentAppointment[serviceIndex].currentTotalServicePrice = - servicesInCurrentAppointment[serviceIndex].currentTotalServicePrice - double.parse((serviceItemsFromApi[index].price) ?? "0.0"); + servicesInCurrentAppointment[serviceIndex].currentTotalServicePrice = servicesInCurrentAppointment[serviceIndex].currentTotalServicePrice - double.parse((serviceItemsFromApi[index].price) ?? "0.0"); servicesInCurrentAppointment[serviceIndex].serviceItems!.removeWhere((element) => element.id == itemId); } notifyListeners(); @@ -617,14 +609,13 @@ class AppointmentsVM extends BaseVM { Column( children: List.generate( selectedService.serviceItems!.length, - (index) => - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - "${selectedService.serviceItems![index].name}".toText(fontSize: 12, color: MyColors.lightTextColor, isBold: true), - "${selectedService.serviceItems![index].price} SAR".toText(fontSize: 12, isBold: true), - ], - ), + (index) => Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + "${selectedService.serviceItems![index].name}".toText(fontSize: 12, color: MyColors.lightTextColor, isBold: true), + "${selectedService.serviceItems![index].price} SAR".toText(fontSize: 12, isBold: true), + ], + ), ), ), Row( @@ -659,9 +650,7 @@ class AppointmentsVM extends BaseVM { Row( crossAxisAlignment: CrossAxisAlignment.end, children: [ - (selectedService.isHomeSelected - ? "${(selectedService.currentTotalServicePrice) + (double.parse((selectedService.rangePricePerKm ?? "0.0")) * totalKms)}" - : "${selectedService.currentTotalServicePrice}") + (selectedService.isHomeSelected ? "${(selectedService.currentTotalServicePrice) + (double.parse((selectedService.rangePricePerKm ?? "0.0")) * totalKms)}" : "${selectedService.currentTotalServicePrice}") .toText(fontSize: 29, isBold: true), 2.width, LocaleKeys.sar.tr().toText(color: MyColors.lightTextColor, fontSize: 16, isBold: true).paddingOnly(bottom: 5), @@ -792,19 +781,19 @@ class AppointmentsVM extends BaseVM { if (genericRespModel.messageStatus == 2 || genericRespModel.data == null) { Utils.hideLoading(context); - Utils.showToast("${genericRespModel.message.toString()}"); + Utils.showToast(genericRespModel.message.toString()); return; } if (genericRespModel.messageStatus == 1) { context.read().onNavbarTapped(1); applyFilterOnAppointmentsVM(appointmentStatusEnum: AppointmentStatusEnum.cancelled); - Utils.showToast("${genericRespModel.message.toString()}"); + Utils.showToast(genericRespModel.message.toString()); getMyAppointments(); Utils.hideLoading(context); navigateReplaceWithNameUntilRoute(context, AppRoutes.dashboard); } } catch (e) { - Utils.showToast("${e.toString()}"); + Utils.showToast(e.toString()); } } @@ -877,9 +866,15 @@ class AppointmentsVM extends BaseVM { return filteredServices; } - getBranchAndServices(int providerId) async { - providerProfileModel = null; - providerProfileModel = await branchRepo.getBranchAndServicesByProviderId(providerId); + Future getProviderProfileWithBranchesAndServices(int providerId) async { + setState(ViewState.busy); + try { + providerProfileModel = await branchRepo.getBranchAndServicesByProviderId(providerId); + } catch (e, s) { + logger.e(s); + setState(ViewState.idle); + Utils.showToast(e.toString()); + } setState(ViewState.idle); } @@ -1079,10 +1074,10 @@ class AppointmentsVM 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"), ""), ); @@ -1427,8 +1422,35 @@ class AppointmentsVM extends BaseVM { setState(ViewState.idle); } - Future addProviderToFavorite({required String serviceProviderID}) async { - setState(ViewState.busy); + Future addProviderToFavorite({required int serviceProviderID, required BuildContext context}) async { + Utils.showLoading(context); + try { + GenericRespModel genericRespModel = await branchRepo.addProviderToFavourite(providerID: serviceProviderID); + Utils.showToast(genericRespModel.message.toString()); + Utils.hideLoading(context); + return genericRespModel.messageStatus == 1; + } catch (e, s) { + logger.e(s); + Utils.hideLoading(context); + Utils.showToast(e.toString()); + return false; + } + } + + Future removeProviderFromFavorite({required int serviceProviderID, required BuildContext context}) async { + Utils.showLoading(context); + + try { + GenericRespModel genericRespModel = await branchRepo.removeProviderFromFavourite(providerID: serviceProviderID); + Utils.hideLoading(context); + Utils.showToast(genericRespModel.message.toString()); + return genericRespModel.messageStatus == 1; + } catch (e, s) { + logger.e(s); + Utils.hideLoading(context); + Utils.showToast(e.toString()); + return false; + } } List currentBranchReviews = []; diff --git a/lib/views/advertisement/components/ads_list_widget.dart b/lib/views/advertisement/components/ads_list_widget.dart index 25c751d..0c10f18 100644 --- a/lib/views/advertisement/components/ads_list_widget.dart +++ b/lib/views/advertisement/components/ads_list_widget.dart @@ -13,7 +13,6 @@ import 'package:mc_common_app/widgets/extensions/extensions_widget.dart'; import 'package:provider/provider.dart'; import 'package:easy_localization/easy_localization.dart'; - class AdsListWidget extends StatelessWidget { final List adsList; final ScrollPhysics? scrollPhysics; @@ -150,8 +149,8 @@ class AdCard extends StatelessWidget { (adDetails.vehicle!.demandAmount!.toInt().toString()).toText(fontSize: 16, isBold: true), 2.width, LocaleKeys.sar.tr().toText( - color: MyColors.lightTextColor, - ), + color: MyColors.lightTextColor, + ), ], ), ), diff --git a/lib/views/appointments/pick_items_view.dart b/lib/views/appointments/pick_items_view.dart index 053e6d2..caffb24 100644 --- a/lib/views/appointments/pick_items_view.dart +++ b/lib/views/appointments/pick_items_view.dart @@ -45,12 +45,10 @@ class _BookProviderAppViewState extends State { providerImageUrl: MyAssets.bnCar, providerLocation: "3km", title: "Al Ahmed Maintenance", - providerRatings: "4.9", + providerRatings: 4.9, ), 12.height, - isReview - ? ReviewAppointmentSection() - : ServicesSelectionSection(), + isReview ? const ReviewAppointmentSection() : const ServicesSelectionSection(), 10.height, ], ), @@ -91,9 +89,7 @@ class ServicesSelectionSection extends StatelessWidget { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - LocaleKeys.selectServicesYouWant - .tr() - .toText(fontSize: 18, isBold: true), + LocaleKeys.selectServicesYouWant.tr().toText(fontSize: 18, isBold: true), 8.height, DropdownField( (DropValue value) {}, @@ -130,8 +126,7 @@ class ServicesSelectionSection extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.end, children: [ "3000".toText(fontSize: 20, isBold: true), - LocaleKeys.sar.tr().toText( - fontSize: 10, isBold: true, color: MyColors.lightTextColor), + LocaleKeys.sar.tr().toText(fontSize: 10, isBold: true, color: MyColors.lightTextColor), ], ), 10.height, @@ -153,22 +148,18 @@ class ReviewAppointmentSection extends StatelessWidget { children: [ LocaleKeys.reviewAppointment.tr().toText(fontSize: 18, isBold: true), 15.height, - LocaleKeys.services.tr().toText( - fontSize: 14, isBold: true, color: MyColors.lightTextColor), + LocaleKeys.services.tr().toText(fontSize: 14, isBold: true, color: MyColors.lightTextColor), LocaleKeys.carEngineCheck.tr().toText(fontSize: 18, isBold: true), 13.height, - LocaleKeys.dateAndTime.tr().toText( - fontSize: 14, isBold: true, color: MyColors.lightTextColor), + LocaleKeys.dateAndTime.tr().toText(fontSize: 14, isBold: true, color: MyColors.lightTextColor), "2 Feb, 2023 at 09:00am".toText(fontSize: 18, isBold: true), 13.height, - LocaleKeys.totalAmount.tr().toText( - fontSize: 14, isBold: true, color: MyColors.lightTextColor), + LocaleKeys.totalAmount.tr().toText(fontSize: 14, isBold: true, color: MyColors.lightTextColor), Row( crossAxisAlignment: CrossAxisAlignment.end, children: [ "3000".toText(fontSize: 20, isBold: true), - LocaleKeys.sar.tr().toText( - fontSize: 10, isBold: true, color: MyColors.lightTextColor), + LocaleKeys.sar.tr().toText(fontSize: 10, isBold: true, color: MyColors.lightTextColor), ], ), 100.height, diff --git a/lib/widgets/common_widgets/provider_details_card.dart b/lib/widgets/common_widgets/provider_details_card.dart index f621d3c..554b3d7 100644 --- a/lib/widgets/common_widgets/provider_details_card.dart +++ b/lib/widgets/common_widgets/provider_details_card.dart @@ -13,7 +13,7 @@ class ProviderDetailsCard extends StatelessWidget { final String title; final String? providerName; final String providerLocation; - final String providerRatings; + final double providerRatings; //TODO: items can be make a generaic, so we can add services/items in the future final List? services; @@ -23,10 +23,10 @@ class ProviderDetailsCard extends StatelessWidget { Key? key, required this.providerImageUrl, required this.title, - this.providerName, required this.providerRatings, required this.providerLocation, this.services, + this.providerName, required this.onCardTapped, }) : super(key: key); @@ -82,18 +82,20 @@ class ProviderDetailsCard extends StatelessWidget { ], ), ), - Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - providerRatings.toText( - isUnderLine: true, - isBold: true, - fontSize: 12, - ), - 2.width, - MyAssets.starIcon.buildSvg(width: 12), - ], - ), + if (providerRatings != 0.0) ...[ + Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + providerRatings.toString().toText( + isUnderLine: true, + isBold: true, + fontSize: 12, + ), + 2.width, + MyAssets.icStar.buildSvg(width: 12), + ], + ), + ], ], ), 8.height, @@ -102,19 +104,15 @@ class ProviderDetailsCard extends StatelessWidget { children: services! .take(2) .map( - (e) => - Row( + (e) => Row( children: [ //TODO: Needs to add icon in the future when added from the provider // MyAssets.maintenanceIcon.buildSvg(), // 8.width, - e.serviceDescription.toString().toText( - fontSize: 12, - isBold: true, - ) + e.serviceDescription.toString().toText(fontSize: 12) ], ), - ) + ) .toList(), ), if (services != null && services!.length > 2)