diff --git a/lib/models/subscriptions_models/provider_subscription_model.dart b/lib/models/subscriptions_models/provider_subscription_model.dart new file mode 100644 index 0000000..46a5c40 --- /dev/null +++ b/lib/models/subscriptions_models/provider_subscription_model.dart @@ -0,0 +1,85 @@ +import 'dart:convert'; + +class ProviderSubscriptionModel { + int? id; + int? subscriptionAppliedId; + int? serviceProviderId; + String? subscriptionName; + String? subscriptionDescription; + DateTime? dateStart; + DateTime? dateEnd; + int? branchesRemaining; + int? subUsersRemaining; + int? subscriptionID; + int? adsRemaining; + bool? isExpired; + bool? isActive; + bool? isUpgradeNow; + bool? isUpgradeLater; + bool? isTrialSubscription; + dynamic currentSubscription; + + ProviderSubscriptionModel({ + this.id, + this.subscriptionAppliedId, + this.serviceProviderId, + this.subscriptionName, + this.subscriptionDescription, + this.dateStart, + this.dateEnd, + this.branchesRemaining, + this.subUsersRemaining, + this.adsRemaining, + this.isExpired, + this.isActive, + this.isUpgradeNow, + this.isUpgradeLater, + this.isTrialSubscription, + this.currentSubscription, + this.subscriptionID + }); + + factory ProviderSubscriptionModel.fromRawJson(String str) => ProviderSubscriptionModel.fromJson(json.decode(str)); + + String toRawJson() => json.encode(toJson()); + + factory ProviderSubscriptionModel.fromJson(Map json) => ProviderSubscriptionModel( + id: json["id"], + subscriptionAppliedId: json["subscriptionAppliedID"], + serviceProviderId: json["serviceProviderID"], + subscriptionID: json["subscriptionID"], + subscriptionName: json["subscriptionName"], + subscriptionDescription: json["subscriptionDescription"], + dateStart: json["dateStart"] == null ? null : DateTime.parse(json["dateStart"]), + dateEnd: json["dateEnd"] == null ? null : DateTime.parse(json["dateEnd"]), + branchesRemaining: json["branchesRemaining"], + subUsersRemaining: json["subUsersRemaining"], + adsRemaining: json["adsRemaining"], + isExpired: json["isExpired"], + isActive: json["isActive"], + isUpgradeNow: json["isUpgradeNow"], + isUpgradeLater: json["isUpgradeLater"], + isTrialSubscription: json["isTrialSubscription"], + currentSubscription: json["currentSubscription"], + ); + + Map toJson() => { + "id": id, + "subscriptionAppliedID": subscriptionAppliedId, + "serviceProviderID": serviceProviderId, + "subscriptionID": subscriptionID, + "subscriptionName": subscriptionName, + "subscriptionDescription": subscriptionDescription, + "dateStart": dateStart?.toIso8601String(), + "dateEnd": dateEnd?.toIso8601String(), + "branchesRemaining": branchesRemaining, + "subUsersRemaining": subUsersRemaining, + "adsRemaining": adsRemaining, + "isExpired": isExpired, + "isActive": isActive, + "isUpgradeNow": isUpgradeNow, + "isUpgradeLater": isUpgradeLater, + "isTrialSubscription":isTrialSubscription, + "currentSubscription": currentSubscription, + }; +} diff --git a/lib/repositories/appointment_repo.dart b/lib/repositories/appointment_repo.dart index 9bffe24..a581c3d 100644 --- a/lib/repositories/appointment_repo.dart +++ b/lib/repositories/appointment_repo.dart @@ -191,7 +191,7 @@ class AppointmentRepoImp implements AppointmentRepo { queryParameters: map, ApiConsts.serviceProvidersAppointmentGet, ); - List appointmentList = List.generate(genericRespModel.data.length, (index) => AppointmentListModel.fromJson(genericRespModel.data[index])); + List appointmentList = await List.generate(genericRespModel.data.length, (index) => AppointmentListModel.fromJson(genericRespModel.data[index])); return appointmentList; } diff --git a/lib/repositories/subscription_repo.dart b/lib/repositories/subscription_repo.dart index 7f5f289..fd2b037 100644 --- a/lib/repositories/subscription_repo.dart +++ b/lib/repositories/subscription_repo.dart @@ -6,6 +6,7 @@ import 'package:mc_common_app/models/general_models/generic_resp_model.dart'; import 'package:mc_common_app/models/general_models/m_response.dart'; import 'package:mc_common_app/models/provider_branches_models/branch_detail_model.dart'; import 'package:mc_common_app/models/subscriptions_models/branch_user_selection_model.dart'; +import 'package:mc_common_app/models/subscriptions_models/provider_subscription_model.dart'; import 'package:mc_common_app/models/subscriptions_models/subscription_model.dart'; import 'package:mc_common_app/models/user_models/branch_user.dart'; @@ -14,22 +15,23 @@ abstract class SubscriptionRepo { Future getMySubscriptions(String? serviceProviderID); - Future getSubscriptionBySP( - String? serviceProviderID, bool isRenew); + Future> getProviderSubscription({String? serviceProviderID}); - Future calculationUpgradePrice( - String? serviceProviderID, String? newSubscription); + Future getSubscriptionBySP(String? serviceProviderID, bool isRenew); + + Future calculationUpgradePrice(String? serviceProviderID, String? newSubscription); Future payForProviderSubscription(Map map); - Future> getSPBranchUser_Get( - Map map); + Future> getSPBranchUser_Get(Map map); } class SubscriptionRepoImp extends SubscriptionRepo { + ApiClient apiClient = injector.get(); + AppState appState = injector.get(); + @override - Future getAllSubscriptions( - String? serviceProviderID) async { + Future getAllSubscriptions(String? serviceProviderID) async { String t = AppState().getUser.data!.accessToken ?? ""; Map queryParameters = {}; if (serviceProviderID != null) { @@ -38,16 +40,11 @@ class SubscriptionRepoImp extends SubscriptionRepo { }; } - return await injector.get().getJsonForObject( - (json) => SubscriptionModel.fromJson(json), - ApiConsts.getAllSubscriptions, - token: t, - queryParameters: queryParameters); + return await injector.get().getJsonForObject((json) => SubscriptionModel.fromJson(json), ApiConsts.getAllSubscriptions, token: t, queryParameters: queryParameters); } @override - Future getSubscriptionBySP( - String? serviceProviderID, bool isRenew) async { + Future getSubscriptionBySP(String? serviceProviderID, bool isRenew) async { String t = AppState().getUser.data!.accessToken ?? ""; Map queryParameters = {}; if (serviceProviderID != null) { @@ -66,8 +63,7 @@ class SubscriptionRepoImp extends SubscriptionRepo { } @override - Future calculationUpgradePrice( - String? serviceProviderID, String? newSubscription) async { + Future calculationUpgradePrice(String? serviceProviderID, String? newSubscription) async { String t = AppState().getUser.data!.accessToken ?? ""; Map queryParameters = {}; if (serviceProviderID != null) { @@ -98,17 +94,15 @@ class SubscriptionRepoImp extends SubscriptionRepo { } @override - Future> getSPBranchUser_Get( - Map map) async { + Future> getSPBranchUser_Get(Map map) async { String t = AppState().getUser.data!.accessToken ?? ""; - GenericRespModel genericRespModel = - await injector.get().getJsonForObject( - (json) => GenericRespModel.fromJson(json), - ApiConsts.getSPBranchUser_Get, - token: t, - queryParameters: map, - ); + GenericRespModel genericRespModel = await injector.get().getJsonForObject( + (json) => GenericRespModel.fromJson(json), + ApiConsts.getSPBranchUser_Get, + token: t, + queryParameters: map, + ); List branchList = []; @@ -117,36 +111,23 @@ class SubscriptionRepoImp extends SubscriptionRepo { List branchUsers = []; // List.from(json["data"]!.map((x) => BranchUsersDatum.fromJson(x)) - branches = List.from(genericRespModel.data["branches"] - ["data"]! - .map((x) => BranchDetailModel.fromJson(x))); - branchUsers = List.from(genericRespModel.data["branchUsers"] - ["data"]! - .map((x) => BranchUser.fromJson(x))); + branches = List.from(genericRespModel.data["branches"]["data"]!.map((x) => BranchDetailModel.fromJson(x))); + branchUsers = List.from(genericRespModel.data["branchUsers"]["data"]!.map((x) => BranchUser.fromJson(x))); for (int i = 0; i < branches.length; i++) { List availableUsers = []; for (int j = 0; j < branchUsers.length; j++) { if (branches[i].id == branchUsers[j].serviceProviderBranchID) { - availableUsers.add(UserSelectionModel( - userId: branchUsers[j].id, - userName: - ("${branchUsers[j].firstName ?? ""} ${branchUsers[j].lastName}"), - isSelected: false)); + availableUsers.add(UserSelectionModel(userId: branchUsers[j].id, userName: ("${branchUsers[j].firstName ?? ""} ${branchUsers[j].lastName}"), isSelected: false)); } } - branchList.add(BranchSelectionModel( - branchId: branches[i].id ?? 0, - branchName: branches[i].branchName ?? "", - isSelected: false, - usersList: availableUsers)); + branchList.add(BranchSelectionModel(branchId: branches[i].id ?? 0, branchName: branches[i].branchName ?? "", isSelected: false, usersList: availableUsers)); } } return branchList; } @override - Future getMySubscriptions( - String? serviceProviderID) async { + Future getMySubscriptions(String? serviceProviderID) async { String t = AppState().getUser.data!.accessToken ?? ""; Map queryParameters = {}; if (serviceProviderID != null) { @@ -154,12 +135,46 @@ class SubscriptionRepoImp extends SubscriptionRepo { "ID": serviceProviderID, }; } - - return await injector.get().getJsonForObject( - (json) => SubscriptionModel.fromJson(json), - ApiConsts.getAllSubscriptions, - token: t, - queryParameters: queryParameters); + return await injector.get().getJsonForObject((json) => SubscriptionModel.fromJson(json), ApiConsts.getAllSubscriptions, token: t, queryParameters: queryParameters); } + + @override + Future> getProviderSubscription({String? serviceProviderID}) async { + Map queryParameters = {}; + if (serviceProviderID != null) { + queryParameters = { + "ServiceProviderID": serviceProviderID, + "IsActiveSubscriptionForProvider": "true", + }; + } + + GenericRespModel adsGenericModel = await apiClient.getJsonForObject( + token: appState.getUser.data!.accessToken, + (json) => GenericRespModel.fromJson(json), + ApiConsts.getMySubscriptions, + queryParameters: queryParameters, + ); + List providerSubList = List.generate(adsGenericModel.data.length, (index) => ProviderSubscriptionModel.fromJson(adsGenericModel.data[index])); + return providerSubList; + } + +// @override +// Future getProviderSubscription( +// String? serviceProviderID) async { +// String t = AppState().getUser.data!.accessToken ?? ""; +// Map queryParameters = {}; +// if (serviceProviderID != null) { +// queryParameters = { +// "ID": serviceProviderID, +// }; +// } +// +// +// return await injector.get().getJsonForObject( +// (json) => SubscriptionModel.fromJson(json), +// ApiConsts.getMySubscriptions, +// token: t, +// queryParameters: queryParameters); +// } } diff --git a/lib/view_models/appointments_view_model.dart b/lib/view_models/appointments_view_model.dart index 33496d8..0cf8865 100644 --- a/lib/view_models/appointments_view_model.dart +++ b/lib/view_models/appointments_view_model.dart @@ -45,11 +45,10 @@ class AppointmentsVM extends BaseVM { final BranchRepo branchRepo; final AppointmentRepo appointmentRepo; - AppointmentsVM( - {required this.commonServices, - required this.appointmentRepo, - required this.commonRepo, - required this.branchRepo}); + AppointmentsVM({required this.commonServices, + required this.appointmentRepo, + required this.commonRepo, + required this.branchRepo}); bool isUpcommingEnabled = true; bool isFetchingLists = false; @@ -72,6 +71,7 @@ class AppointmentsVM extends BaseVM { List branchCategories = []; bool isHomeTapped = false; + bool isShowEmptyMessage = false; List serviceAppointmentScheduleList = []; @@ -99,7 +99,7 @@ class AppointmentsVM extends BaseVM { Future onItemsSelectedInService() async { if (currentServiceSelection != null) { int index = servicesInCurrentAppointment.indexWhere((element) => - element.serviceId == currentServiceSelection!.serviceId!); + element.serviceId == currentServiceSelection!.serviceId!); if (index == -1) { double totalPrice = 0.0; @@ -115,8 +115,7 @@ class AppointmentsVM extends BaseVM { } } - Future onPayNowPressedForAppointment( - {required BuildContext context, required int appointmentID}) async { + Future onPayNowPressedForAppointment({required BuildContext context, required int appointmentID}) async { context .read() .updateAppointmentIdsForPayment(ids: [appointmentID]); @@ -130,7 +129,7 @@ class AppointmentsVM extends BaseVM { List appointmentIdsList = []; try { GenericRespModel genericRespModel = - await appointmentRepo.createServiceAppointment( + await appointmentRepo.createServiceAppointment( schedules: serviceAppointmentScheduleList, serviceProviderID: selectedBranchModel!.serviceProviderId ?? 0, ); @@ -178,8 +177,7 @@ class AppointmentsVM extends BaseVM { } } - Future onConfirmAppointmentPressed( - {required BuildContext context, required appointmentId}) async { + Future onConfirmAppointmentPressed({required BuildContext context, required appointmentId}) async { context .read() .updateAppointmentIdsForPayment(ids: [appointmentId]); @@ -187,13 +185,12 @@ class AppointmentsVM extends BaseVM { arguments: PaymentTypes.appointment); } - Future onCancelAppointmentPressed( - {required BuildContext context, - required AppointmentListModel appointmentListModel}) async { + Future onCancelAppointmentPressed({required BuildContext context, + required AppointmentListModel appointmentListModel}) async { Utils.showLoading(context); try { GenericRespModel genericRespModel = - await appointmentRepo.cancelOrRescheduleServiceAppointment( + await appointmentRepo.cancelOrRescheduleServiceAppointment( serviceAppointmentID: appointmentListModel.id ?? 0, serviceSlotID: appointmentListModel.serviceSlotID ?? 0, appointmentScheduleAction: 2, // 1 for Reschedule and 2 for Cancel @@ -240,7 +237,7 @@ class AppointmentsVM extends BaseVM { } SelectionModel branchSelectedCategoryId = - SelectionModel(selectedOption: "", selectedId: -1, errorValue: ""); + SelectionModel(selectedOption: "", selectedId: -1, errorValue: ""); void updateProviderCategoryId(SelectionModel id) { branchSelectedCategoryId = id; @@ -256,18 +253,18 @@ class AppointmentsVM extends BaseVM { void updateBranchServiceId(SelectionModel id) async { branchSelectedServiceId = id; currentServiceSelection = branchServices.firstWhere( - (element) => element.serviceProviderServiceId == id.selectedId); + (element) => element.serviceProviderServiceId == id.selectedId); notifyListeners(); } void removeServiceInCurrentAppointment(int index) { int serviceId = servicesInCurrentAppointment - .elementAt(index) - .serviceProviderServiceId ?? + .elementAt(index) + .serviceProviderServiceId ?? -1; allSelectedItemsInAppointments.removeWhere( - (element) => element.serviceProviderServiceId == serviceId); + (element) => element.serviceProviderServiceId == serviceId); servicesInCurrentAppointment.removeAt(index); notifyListeners(); } @@ -314,9 +311,8 @@ class AppointmentsVM extends BaseVM { notifyListeners(); } - applyFilterOnAppointmentsVM( - {required AppointmentStatusEnum appointmentStatusEnum, - bool isNeedCustomerFilter = false}) { + applyFilterOnAppointmentsVM({required AppointmentStatusEnum appointmentStatusEnum, + bool isNeedCustomerFilter = false}) { // isNeedCustomerFilter IS ONLY FOR THE PROVIDER APP if (appointmentsFilterOptions.isEmpty) return; for (var value in appointmentsFilterOptions) { @@ -336,17 +332,15 @@ class AppointmentsVM extends BaseVM { if (appointmentStatusEnum.getIdFromAppointmentStatusEnum() == 0) { myFilteredAppointments = myAppointments; if (isNeedCustomerFilter) findAppointmentsBasedOnCustomers(); - notifyListeners(); return; } myFilteredAppointments = myAppointments .where((element) => - element.appointmentStatusID! == - appointmentStatusEnum.getIdFromAppointmentStatusEnum()) + element.appointmentStatusID! == + appointmentStatusEnum.getIdFromAppointmentStatusEnum()) .toList(); if (isNeedCustomerFilter) findAppointmentsBasedOnCustomers(); - notifyListeners(); } findAppointmentsBasedOnCustomers() { @@ -382,32 +376,35 @@ class AppointmentsVM extends BaseVM { // }).toList(); } - Future getMyAppointments({bool isNeedToRebuild = false}) async { - if (isNeedToRebuild) setState(ViewState.busy); + Future getMyAppointments() async { + setState(ViewState.busy); myAppointments = - await appointmentRepo.getMyAppointmentsForCustomersByFilters(); - // myFilteredAppointments = myAppointments; + await appointmentRepo.getMyAppointmentsForCustomersByFilters(); + myFilteredAppointments = myAppointments; myUpComingAppointments = myAppointments .where((element) => - element.appointmentStatusEnum == AppointmentStatusEnum.confirmed) + element.appointmentStatusEnum == AppointmentStatusEnum.confirmed) .toList(); - setState(ViewState.idle); + applyFilterOnAppointmentsVM( appointmentStatusEnum: AppointmentStatusEnum.allAppointments); + if (myUpComingAppointments.isEmpty) { + isShowEmptyMessage = true; + } + setState(ViewState.idle); notifyListeners(); } AppointmentSlots? appointmentSlots; - Future getAppointmentSlotsInfo( - {required Map map, - required BuildContext context, - bool isNeedToRebuild = false}) async { + Future getAppointmentSlotsInfo({required Map map, + required BuildContext context, + bool isNeedToRebuild = false}) async { if (isNeedToRebuild) setState(ViewState.busy); try { MResponse genericRespModel = - await appointmentRepo.getAppointmentSlots(map); + await appointmentRepo.getAppointmentSlots(map); if (genericRespModel.messageStatus == 1) { appointmentSlots = AppointmentSlots.fromJson(genericRespModel.data); } else { @@ -418,17 +415,14 @@ class AppointmentsVM extends BaseVM { } } - Future getMyAppointmentsForProvider(Map map, - {bool isNeedToRebuild = false}) async { - if (isNeedToRebuild) setState(ViewState.busy); - + Future getMyAppointmentsForProvider(Map map,) async { + setState(ViewState.busy); myAppointments = await appointmentRepo.getMyAppointmentsForProvider(map); myFilteredAppointments = myAppointments; - myUpComingAppointments = myAppointments + myUpComingAppointments = await myAppointments .where((element) => - element.appointmentStatusEnum == AppointmentStatusEnum.booked) + element.appointmentStatusEnum == AppointmentStatusEnum.confirmed) .toList(); - applyFilterOnAppointmentsVM( appointmentStatusEnum: AppointmentStatusEnum.allAppointments, isNeedCustomerFilter: true); @@ -440,7 +434,7 @@ class AppointmentsVM extends BaseVM { if (isNeedToRebuild) setState(ViewState.busy); try { MResponse genericRespModel = - await appointmentRepo.updateAppointmentStatus(map); + await appointmentRepo.updateAppointmentStatus(map); if (genericRespModel.messageStatus == 1) { Utils.showToast(LocaleKeys.appointmentStatusUpdated.tr()); @@ -457,7 +451,7 @@ class AppointmentsVM extends BaseVM { if (isNeedToRebuild) setState(ViewState.busy); try { MResponse genericRespModel = - await appointmentRepo.updateAppointmentPaymentStatus(map); + await appointmentRepo.updateAppointmentPaymentStatus(map); if (genericRespModel.messageStatus == 1) { Utils.showToast(LocaleKeys.paymentStatusUpdated.tr()); @@ -473,7 +467,7 @@ class AppointmentsVM extends BaseVM { {bool isNeedToRebuild = false}) async { if (isNeedToRebuild) setState(ViewState.busy); MResponse genericRespModel = - await appointmentRepo.createMergeAppointment(map); + await appointmentRepo.createMergeAppointment(map); return genericRespModel; } @@ -484,12 +478,12 @@ class AppointmentsVM extends BaseVM { myFilteredAppointments2[selectedAppointmentIndex] .customerAppointmentList![currentIndex] .isSelected = !(myFilteredAppointments2[selectedAppointmentIndex] - .customerAppointmentList?[currentIndex] - .isSelected ?? + .customerAppointmentList?[currentIndex] + .isSelected ?? false); int count = countSelected(myFilteredAppointments2[selectedAppointmentIndex] - .customerAppointmentList ?? + .customerAppointmentList ?? []); if (count > 1) inNeedToEnableMergeButton = true; @@ -505,8 +499,7 @@ class AppointmentsVM extends BaseVM { .length; } - updateSelectedAppointmentDate( - {required int dateIndex, required int scheduleIndex}) { + updateSelectedAppointmentDate({required int dateIndex, required int scheduleIndex}) { for (var element in serviceAppointmentScheduleList[scheduleIndex] .customTimeDateSlotList!) { element.date!.isSelected = false; @@ -534,8 +527,7 @@ class AppointmentsVM extends BaseVM { notifyListeners(); } - updateSelectedAppointmentSlotByDate( - {required int scheduleIndex, required int slotIndex}) { + updateSelectedAppointmentSlotByDate({required int scheduleIndex, required int slotIndex}) { for (var element in serviceAppointmentScheduleList[scheduleIndex] .customTimeDateSlotList!) { for (var element in element.availableSlots!) { @@ -543,17 +535,17 @@ class AppointmentsVM extends BaseVM { } } int index = - serviceAppointmentScheduleList[scheduleIndex].selectedDateIndex!; + serviceAppointmentScheduleList[scheduleIndex].selectedDateIndex!; serviceAppointmentScheduleList[scheduleIndex] .customTimeDateSlotList![index] .availableSlots![slotIndex] .isSelected = true; serviceAppointmentScheduleList[scheduleIndex] - .selectedCustomTimeDateSlotModel! - .availableSlots = - serviceAppointmentScheduleList[scheduleIndex] - .customTimeDateSlotList![index] - .availableSlots!; + .selectedCustomTimeDateSlotModel! + .availableSlots = + serviceAppointmentScheduleList[scheduleIndex] + .customTimeDateSlotList![index] + .availableSlots!; notifyListeners(); } @@ -568,7 +560,7 @@ class AppointmentsVM extends BaseVM { onItemUpdateOrSelected(int index, bool selected, int itemId) { int serviceIndex = servicesInCurrentAppointment.indexWhere( - (element) => element.serviceId == currentServiceSelection!.serviceId!); + (element) => element.serviceId == currentServiceSelection!.serviceId!); // print("servicesInCurrentAppointment: ${servicesInCurrentAppointment.length}"); // if (serviceIndex == -1) { // return; @@ -588,7 +580,7 @@ class AppointmentsVM extends BaseVM { .add(serviceItemsFromApi[index]); servicesInCurrentAppointment[serviceIndex].currentTotalServicePrice = servicesInCurrentAppointment[serviceIndex] - .currentTotalServicePrice + + .currentTotalServicePrice + double.parse((serviceItemsFromApi[index].price) ?? "0.0"); } } @@ -637,7 +629,7 @@ class AppointmentsVM extends BaseVM { String selectSubServicesError = ""; SelectionModel branchSelectedServiceId = - SelectionModel(selectedOption: "", selectedId: -1, errorValue: ""); + SelectionModel(selectedOption: "", selectedId: -1, errorValue: ""); void updatePickHomeLocationError(String value) { pickHomeLocationError = value; @@ -677,8 +669,7 @@ class AppointmentsVM extends BaseVM { return totalPrice.toString(); } - void openTheAddServiceBottomSheet( - BuildContext context, AppointmentsVM appointmentsVM) { + void openTheAddServiceBottomSheet(BuildContext context, AppointmentsVM appointmentsVM) { showModalBottomSheet( context: context, isScrollControlled: true, @@ -689,8 +680,7 @@ class AppointmentsVM extends BaseVM { ); } - void priceBreakDownClicked( - BuildContext context, ServiceModel selectedService) { + void priceBreakDownClicked(BuildContext context, ServiceModel selectedService) { showModalBottomSheet( context: context, isScrollControlled: true, @@ -708,17 +698,18 @@ 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( @@ -764,16 +755,16 @@ class AppointmentsVM extends BaseVM { crossAxisAlignment: CrossAxisAlignment.end, children: [ (selectedService.isHomeSelected - ? "${(selectedService.currentTotalServicePrice) + (double.parse((selectedService.rangePricePerKm ?? "0.0")) * totalKms)}" - : "${selectedService.currentTotalServicePrice}") + ? "${(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) + color: MyColors.lightTextColor, + fontSize: 16, + isBold: true) .paddingOnly(bottom: 5), ], ) @@ -834,7 +825,7 @@ class AppointmentsVM extends BaseVM { } serviceAppointmentScheduleList = - await appointmentRepo.mergeServiceIntoAvailableSchedules( + await appointmentRepo.mergeServiceIntoAvailableSchedules( serviceItemIdsForHome: serviceItemIdsForHome, serviceItemIdsForWorkshop: serviceItemIdsForWorkshop, ); @@ -860,9 +851,8 @@ class AppointmentsVM extends BaseVM { notifyListeners(); } - Future onRescheduleAppointmentPressed( - {required BuildContext context, - required AppointmentListModel appointmentListModel}) async { + Future onRescheduleAppointmentPressed({required BuildContext context, + required AppointmentListModel appointmentListModel}) async { Utils.showLoading(context); List serviceItemIdsForHome = []; @@ -880,7 +870,7 @@ class AppointmentsVM extends BaseVM { } serviceAppointmentScheduleList = - await appointmentRepo.mergeServiceIntoAvailableSchedules( + await appointmentRepo.mergeServiceIntoAvailableSchedules( serviceItemIdsForHome: serviceItemIdsForHome, serviceItemIdsForWorkshop: serviceItemIdsForWorkshop, ); @@ -902,14 +892,13 @@ class AppointmentsVM extends BaseVM { notifyListeners(); } - Future onRescheduleAppointmentConfirmPressed( - {required BuildContext context, - required int appointmentId, - required int selectedSlotId}) async { + Future onRescheduleAppointmentConfirmPressed({required BuildContext context, + required int appointmentId, + required int selectedSlotId}) async { Utils.showLoading(context); try { GenericRespModel genericRespModel = - await appointmentRepo.cancelOrRescheduleServiceAppointment( + await appointmentRepo.cancelOrRescheduleServiceAppointment( serviceAppointmentID: appointmentId, serviceSlotID: selectedSlotId, appointmentScheduleAction: 1, // 1 for Reschedule and 2 for Cancel @@ -972,14 +961,13 @@ class AppointmentsVM extends BaseVM { setState(ViewState.idle); } - Future getAllNearBranches( - {bool isNeedToRebuild = false, bool isFromRefresh = false}) async { + Future getAllNearBranches({bool isNeedToRebuild = false, bool isFromRefresh = false}) async { nearbyBranches.clear(); if (isNeedToRebuild) setState(ViewState.busy); if (isFromRefresh) { var selectedBranch = - branchesFilterOptions.firstWhere((element) => element.isSelected); + branchesFilterOptions.firstWhere((element) => element.isSelected); nearbyBranches = await branchRepo .getBranchesByFilters(categoryIdsList: [selectedBranch.id]); setState(ViewState.idle); @@ -1023,7 +1011,7 @@ class AppointmentsVM extends BaseVM { getBranchAndServices(int providerId) async { providerProfileModel = null; providerProfileModel = - await branchRepo.getBranchAndServicesByProviderId(providerId); + await branchRepo.getBranchAndServicesByProviderId(providerId); setState(ViewState.idle); } @@ -1058,8 +1046,7 @@ class AppointmentsVM extends BaseVM { // Provider Filter List branchFilterProviderSearchHistory = []; - void removeBranchFilterProviderSearchHistory( - {bool isClear = false, required int index}) { + void removeBranchFilterProviderSearchHistory({bool isClear = false, required int index}) { if (isClear) { branchFilterProviderSearchHistory.clear(); notifyListeners(); @@ -1082,7 +1069,7 @@ class AppointmentsVM extends BaseVM { } SelectionModel branchFilterSelectedProviderId = - SelectionModel(selectedOption: "", selectedId: -1, errorValue: ""); + SelectionModel(selectedOption: "", selectedId: -1, errorValue: ""); void updateBranchFilterSelectedProviderId(SelectionModel id, {bool isForSearch = false}) async { @@ -1102,8 +1089,7 @@ class AppointmentsVM extends BaseVM { // Category Filter List branchFilterCategorySearchHistory = []; - void removeBranchFilterCategorySearchHistory( - {bool isClear = false, required int index}) { + void removeBranchFilterCategorySearchHistory({bool isClear = false, required int index}) { if (isClear) { branchFilterCategorySearchHistory.clear(); notifyListeners(); @@ -1126,13 +1112,13 @@ class AppointmentsVM extends BaseVM { } SelectionModel branchFilterSelectedCategoryId = - SelectionModel(selectedOption: "", selectedId: -1, errorValue: ""); + SelectionModel(selectedOption: "", selectedId: -1, errorValue: ""); void updateBranchFilterSelectedCategoryId(SelectionModel id, {bool isForSearch = false}) async { if (isForSearch) { DropValue categoryDrop = - categoryDropList.firstWhere((element) => element.id == id.selectedId); + categoryDropList.firstWhere((element) => element.id == id.selectedId); if (!ifAlreadyExist( list: branchFilterCategorySearchHistory, value: categoryDrop)) { addBranchFilterCategorySearchHistory(value: categoryDrop); @@ -1146,8 +1132,7 @@ class AppointmentsVM extends BaseVM { // Services Filter List branchFilterServicesSearchHistory = []; - void removeBranchFilterServicesSearchHistory( - {bool isClear = false, required int index}) { + void removeBranchFilterServicesSearchHistory({bool isClear = false, required int index}) { if (isClear) { branchFilterServicesSearchHistory.clear(); notifyListeners(); @@ -1170,13 +1155,13 @@ class AppointmentsVM extends BaseVM { } SelectionModel branchFilterSelectedServiceId = - SelectionModel(selectedOption: "", selectedId: -1, errorValue: ""); + SelectionModel(selectedOption: "", selectedId: -1, errorValue: ""); void updateBranchFilterSelectedServiceId(SelectionModel id, {bool isForSearch = false}) async { if (isForSearch) { DropValue serviceDrop = - servicesDropList.firstWhere((element) => element.id == id.selectedId); + servicesDropList.firstWhere((element) => element.id == id.selectedId); if (!ifAlreadyExist( list: branchFilterServicesSearchHistory, value: serviceDrop)) { addBranchFilterServicesSearchHistory(value: serviceDrop); @@ -1220,7 +1205,7 @@ class AppointmentsVM extends BaseVM { providersDropList.clear(); setOnlyState(ViewState.busy); List providers = - await branchRepo.getAllProvidersWitheBasicData(); + await branchRepo.getAllProvidersWitheBasicData(); for (var element in providers) { providersDropList.add( DropValue(element.id ?? 0, element.providerName ?? "N/A", ""), @@ -1239,10 +1224,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"), ""), ); @@ -1330,8 +1315,7 @@ class AppointmentsVM extends BaseVM { setState(ViewState.idle); } - Future getBranchesBasedOnCategoryFilters( - {required int categoryId}) async { + Future getBranchesBasedOnCategoryFilters({required int categoryId}) async { if (categoryId == 0) { await getAllNearBranches(); return; @@ -1339,7 +1323,7 @@ class AppointmentsVM extends BaseVM { setState(ViewState.busy); nearbyBranches.clear(); nearbyBranches = - await branchRepo.getBranchesByFilters(categoryIdsList: [categoryId]); + await branchRepo.getBranchesByFilters(categoryIdsList: [categoryId]); setState(ViewState.idle); } @@ -1347,8 +1331,7 @@ class AppointmentsVM extends BaseVM { List branchesDropList = []; - Future fetchAllBranchesBySelectedProviderId( - {required List providersIdsList}) async { + Future fetchAllBranchesBySelectedProviderId({required List providersIdsList}) async { branchesDropList.clear(); setOnlyState(ViewState.busy); List providers = await branchRepo.getBranchesByFilters( @@ -1378,8 +1361,7 @@ class AppointmentsVM extends BaseVM { // Provider Filter For Appointments List appointmentFilterProviderSearchHistory = []; - void removeAppointmentFilterProviderSearchHistory( - {bool isClear = false, required int index}) { + void removeAppointmentFilterProviderSearchHistory({bool isClear = false, required int index}) { if (isClear) { appointmentFilterProviderSearchHistory.clear(); notifyListeners(); @@ -1416,7 +1398,7 @@ class AppointmentsVM extends BaseVM { } SelectionModel appointmentFilterSelectedProviderId = - SelectionModel(selectedOption: "", selectedId: -1, errorValue: ""); + SelectionModel(selectedOption: "", selectedId: -1, errorValue: ""); void updateAppointmentFilterSelectedProviderId(SelectionModel id, {bool isForSearch = false}) async { @@ -1436,8 +1418,7 @@ class AppointmentsVM extends BaseVM { List appointmentFilterBranchSearchHistory = []; - void removeAppointmentFilterBranchSearchHistory( - {bool isClear = false, required int index}) { + void removeAppointmentFilterBranchSearchHistory({bool isClear = false, required int index}) { if (isClear) { appointmentFilterBranchSearchHistory.clear(); notifyListeners(); @@ -1460,13 +1441,13 @@ class AppointmentsVM extends BaseVM { } SelectionModel appointmentFilterSelectedBranchId = - SelectionModel(selectedOption: "", selectedId: -1, errorValue: ""); + SelectionModel(selectedOption: "", selectedId: -1, errorValue: ""); void updateAppointmentFilterSelectedBranchId(SelectionModel id, {bool isForSearch = false}) async { if (isForSearch) { DropValue branchesDrop = - branchesDropList.firstWhere((element) => element.id == id.selectedId); + branchesDropList.firstWhere((element) => element.id == id.selectedId); if (!ifAlreadyExist( list: appointmentFilterBranchSearchHistory, value: branchesDrop)) { addAppointmentFilterBranchSearchHistory(value: branchesDrop); @@ -1480,8 +1461,7 @@ class AppointmentsVM extends BaseVM { List appointmentFilterCategorySearchHistory = []; - void removeAppointmentFilterCategorySearchHistory( - {bool isClear = false, required int index}) { + void removeAppointmentFilterCategorySearchHistory({bool isClear = false, required int index}) { if (isClear) { appointmentFilterCategorySearchHistory.clear(); notifyListeners(); @@ -1504,13 +1484,13 @@ class AppointmentsVM extends BaseVM { } SelectionModel appointmentFilterSelectedCategoryId = - SelectionModel(selectedOption: "", selectedId: -1, errorValue: ""); + SelectionModel(selectedOption: "", selectedId: -1, errorValue: ""); void updateAppointmentFilterSelectedCategoryId(SelectionModel id, {bool isForSearch = false}) async { if (isForSearch) { DropValue categoryDrop = - categoryDropList.firstWhere((element) => element.id == id.selectedId); + categoryDropList.firstWhere((element) => element.id == id.selectedId); if (!ifAlreadyExist( list: appointmentFilterCategorySearchHistory, value: categoryDrop)) { addAppointmentFilterCategorySearchHistory(value: categoryDrop); @@ -1522,8 +1502,7 @@ class AppointmentsVM extends BaseVM { List appointmentFilterServicesSearchHistory = []; - void removeAppointmentFilterServicesSearchHistory( - {bool isClear = false, required int index}) { + void removeAppointmentFilterServicesSearchHistory({bool isClear = false, required int index}) { if (isClear) { appointmentFilterServicesSearchHistory.clear(); notifyListeners(); @@ -1546,13 +1525,13 @@ class AppointmentsVM extends BaseVM { } SelectionModel appointmentFilterSelectedServiceId = - SelectionModel(selectedOption: "", selectedId: -1, errorValue: ""); + SelectionModel(selectedOption: "", selectedId: -1, errorValue: ""); void updateAppointmentFilterSelectedServiceId(SelectionModel id, {bool isForSearch = false}) async { if (isForSearch) { DropValue servicesDrop = - servicesDropList.firstWhere((element) => element.id == id.selectedId); + servicesDropList.firstWhere((element) => element.id == id.selectedId); if (!ifAlreadyExist( list: appointmentFilterServicesSearchHistory, value: servicesDrop)) { addAppointmentFilterServicesSearchHistory(value: servicesDrop); @@ -1612,7 +1591,7 @@ class AppointmentsVM extends BaseVM { } myAppointments = - await appointmentRepo.getMyAppointmentsForCustomersByFilters( + await appointmentRepo.getMyAppointmentsForCustomersByFilters( providerIdsList: providersIdsList.isNotEmpty ? providersIdsList : null, categoryIdsList: categoryIdsList.isNotEmpty ? categoryIdsList : null, serviceIdsList: servicesIdsList.isNotEmpty ? servicesIdsList : null, diff --git a/lib/view_models/service_view_model.dart b/lib/view_models/service_view_model.dart index f348195..07f928c 100644 --- a/lib/view_models/service_view_model.dart +++ b/lib/view_models/service_view_model.dart @@ -350,8 +350,7 @@ class ServiceVM extends BaseVM { setState(ViewState.idle); } - Future getAllCountriesList( - BranchDetailModel? branchData, String countryCode) async { + Future getAllCountriesList(BranchDetailModel? branchData, String countryCode) async { cities = null; country = null; setState(ViewState.busy); @@ -386,8 +385,7 @@ class ServiceVM extends BaseVM { setState(ViewState.idle); } - Future getAllCities( - BranchDetailModel? branchData, String countryCode) async { + Future getAllCities(BranchDetailModel? branchData, String countryCode) async { setState(ViewState.busy); citiesDropList = []; cities = null; @@ -432,16 +430,15 @@ class ServiceVM extends BaseVM { cityId.toString(), address, latitude.toString(), longitude.toString()); } - Future updateBranch( - int id, - String branchName, - String branchDescription, - String cityId, - String address, - String latitude, - String longitude, { - bool isNeedToDelete = true, - }) async { + Future updateBranch(int id, + String branchName, + String branchDescription, + String cityId, + String address, + String latitude, + String longitude, { + bool isNeedToDelete = true, + }) async { return await branchRepo.updateBranch( id ?? 0, branchName, @@ -488,10 +485,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"), "", ), @@ -551,8 +548,7 @@ class ServiceVM extends BaseVM { List? matchedServices; bool isAllSelected = false; - Future getAllMatchedServices( - int oldBranchId, int newBranchId, int categoryId) async { + Future getAllMatchedServices(int oldBranchId, int newBranchId, int categoryId) async { matchedServices = null; final MResponse response = await branchRepo.getMatchedServices( oldBranchId, newBranchId, categoryId); diff --git a/lib/view_models/subscriptions_view_model.dart b/lib/view_models/subscriptions_view_model.dart index 49e6d5e..546ed13 100644 --- a/lib/view_models/subscriptions_view_model.dart +++ b/lib/view_models/subscriptions_view_model.dart @@ -3,6 +3,7 @@ import 'dart:convert'; import 'package:mc_common_app/classes/app_state.dart'; import 'package:mc_common_app/models/general_models/m_response.dart'; import 'package:mc_common_app/models/subscriptions_models/branch_user_selection_model.dart'; +import 'package:mc_common_app/models/subscriptions_models/provider_subscription_model.dart'; import 'package:mc_common_app/models/subscriptions_models/subscription_model.dart'; import 'package:mc_common_app/utils/enums.dart'; import 'package:mc_common_app/view_models/base_view_model.dart'; @@ -19,6 +20,7 @@ class SubscriptionsVM extends BaseVM { late DropValue selectedMothlyTab; List monthlyTabs = []; late SubscriptionModel allSubscriptions; + List mySubscriptionsBySp = []; List tempSubscriptions = []; //My Subscriptions @@ -110,17 +112,12 @@ class SubscriptionsVM extends BaseVM { return mResponse; } - Future createSubscriptionOrder(int subscriptionId, bool isStartNow, bool isReview, String amount, {bool isDegrade = false, List? listOfBranches, List? listOfUsers}) async { + Future createSubscriptionOrder(int subscriptionId, bool isStartNow, bool isRenew, {bool isDegrade = false, List? listOfBranches, List? listOfUsers}) async { Map map = { - // "id": subscription.id.toString(), - // "payFortOrderID": 0, "providerID": AppState().getUser.data?.userInfo?.providerId.toString() ?? "", "subscriptionID": subscriptionId.toString(), "isStartNow": isStartNow.toString(), - "subscriptionAmount": amount, - "isRenew": isReview.toString() - // "listOfBranches": [], - // "listOfUsers": [] + "isRenew": isRenew.toString() }; MResponse mResponse = await subscriptionRepo.payForProviderSubscription(map); return mResponse; @@ -175,4 +172,13 @@ class SubscriptionsVM extends BaseVM { setState(ViewState.error); } } + + // My Provider Subscription + getMySubscriptionsBySP(String? serviceProviderID) async { + setState(ViewState.busy); + if (mySubscriptionsBySp.isEmpty) { + mySubscriptionsBySp = await subscriptionRepo.getProviderSubscription(serviceProviderID: serviceProviderID); + } + setState(ViewState.idle); + } } diff --git a/lib/view_models/user_view_model.dart b/lib/view_models/user_view_model.dart index 27e45d6..34b65f2 100644 --- a/lib/view_models/user_view_model.dart +++ b/lib/view_models/user_view_model.dart @@ -350,13 +350,10 @@ class UserVM extends BaseVM { Future performBasicOtpLoginSelectionPage(BuildContext context, {required String userToken, required AppType appType, String? loginType}) async { if (loginType == "3" || loginType == "4") { - Utils.showLoading(context); + //Utils.showLoading(context); LoginPasswordRespModel user = await userRepo.loginV2OTP(userToken, loginType!); - Utils.hideLoading(context); if (user.messageStatus == 1) { - Utils.showLoading(context); Response response2 = await userRepo.loginV2OTPVerify(user.data!.userToken ?? "", "9999"); - Utils.hideLoading(context); RegisterUserRespModel verifiedUser = RegisterUserRespModel.fromJson(jsonDecode(response2.body)); if (verifiedUser.messageStatus == 1) { User user = User.fromJson(jsonDecode(response2.body)); @@ -370,7 +367,6 @@ class UserVM extends BaseVM { navigateReplaceWithName(context, AppRoutes.dashboard); } else { Utils.showToast(LocaleKeys.onlyProviderApp.tr()); - //("Sorry, Only Customer's can log in this app"); } } else if (user.data!.userInfo!.roleId == 4) { if (user.data!.userInfo!.roleId == 4) { @@ -381,17 +377,17 @@ class UserVM extends BaseVM { SharedPrefManager.setData(jsonEncode(user.data!.userInfo!.toJson())); navigateReplaceWithName(context, AppRoutes.dashboard); } else { - Utils.showToast(LocaleKeys.onlyCustomerApp.tr()); + Utils.showToast(LocaleKeys.onlyCustomerApp.tr()); } } } else { - Utils.showToast(verifiedUser.message ?? ""); + Utils.showToast(verifiedUser.message ?? ""); } } } else { - Utils.showLoading(context); + // Utils.showLoading(context); LoginPasswordRespModel user = await userRepo.loginV2OTP(userToken, "1"); - Utils.hideLoading(context); + // Utils.hideLoading(context); if (user.messageStatus == 1) { showMDialog(context, child: OtpDialog( onClick: (String code) async { @@ -628,6 +624,7 @@ class UserVM extends BaseVM { String uName = await SharedPrefManager.getPhoneOrEmail(); String pass = await SharedPrefManager.getUserPassword(); if (!loginOtherAccount && uName.isNotEmpty && pass.isNotEmpty) { + getAvailBio(); if (uName.isNum()) { performBasicOtpLoginWithPasswordPage(context, type: ClassType.NUMBER, countryCode: null, phoneNum: uName, password: pass); } diff --git a/lib/views/appointments/widgets/customer_appointment_slider_widget.dart b/lib/views/appointments/widgets/customer_appointment_slider_widget.dart index d6c0eaa..5eb7be0 100644 --- a/lib/views/appointments/widgets/customer_appointment_slider_widget.dart +++ b/lib/views/appointments/widgets/customer_appointment_slider_widget.dart @@ -1,107 +1,149 @@ import 'package:carousel_slider/carousel_slider.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/svg.dart'; +import 'package:mc_common_app/classes/app_state.dart'; import 'package:mc_common_app/classes/consts.dart'; import 'package:mc_common_app/config/routes.dart'; import 'package:mc_common_app/extensions/int_extensions.dart'; import 'package:mc_common_app/extensions/string_extensions.dart'; import 'package:mc_common_app/models/appointments_models/appointment_list_model.dart'; import 'package:mc_common_app/theme/colors.dart'; +import 'package:mc_common_app/utils/enums.dart'; import 'package:mc_common_app/utils/navigator.dart'; +import 'package:mc_common_app/view_models/appointments_view_model.dart'; import 'package:mc_common_app/view_models/dashboard_view_model_customer.dart'; import 'package:mc_common_app/views/advertisement/custom_add_button.dart'; import 'package:mc_common_app/widgets/extensions/extensions_widget.dart'; import 'package:provider/provider.dart'; -//TODO: Need to make onTapped dynamic class CustomerAppointmentSliderWidget extends StatelessWidget { - final List myUpComingAppointments; - bool isNeedToShowEmptyMessage; - Function()? onAppointmentClick; + Function(AppointmentListModel)? onAppointmentClick; - CustomerAppointmentSliderWidget({Key? key, - required this.myUpComingAppointments, - this.isNeedToShowEmptyMessage = false, - this.onAppointmentClick}) - : super(key: key); + CustomerAppointmentSliderWidget({Key? key, this.onAppointmentClick}) : super(key: key); - @override - Widget build(BuildContext context) { - if (myUpComingAppointments.isEmpty) { - if (isNeedToShowEmptyMessage) - return "No Upcoming Appointment Available".toText().paddingAll(21); - return CustomAddButton( - needsBorder: true, - bgColor: MyColors.white, - onTap: () => context.read().onNavbarTapped(0), - text: "Add New Appointment", - icon: Container( - height: 24, - width: 24, - decoration: const BoxDecoration( - shape: BoxShape.circle, color: MyColors.darkTextColor), - child: const Icon(Icons.add, color: MyColors.white), - ), - ).padding(EdgeInsets.symmetric(vertical: 10, horizontal: 21)); - return Container( - height: 86, - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Container( - height: 24, - width: 24, - decoration: BoxDecoration( - shape: BoxShape.circle, color: MyColors.darkTextColor), - child: Icon( - Icons.add, - color: MyColors.white, - ), - ), - SizedBox(width: 10), - "Add New Appointment".toText( - fontSize: 15, - isBold: true, - color: MyColors.lightTextColor, - ), - ], - ), - ).onPress(() {}).toWhiteContainer( - width: double.infinity, - margin: EdgeInsets.symmetric(horizontal: 21, vertical: 10)); - } + Widget getCorouselWidget(AppType appType, AppointmentsVM appointmentsVM) { return CarouselSlider.builder( options: CarouselOptions( - height: 140, + height: 110, viewportFraction: 1.0, enlargeCenterPage: false, enableInfiniteScroll: false, ), - itemCount: myUpComingAppointments.length, + itemCount: appointmentsVM.myUpComingAppointments.length, itemBuilder: (BuildContext context, int itemIndex, int pageViewIndex) => BuildAppointmentContainerForCustomer( isForHome: true, - appointmentListModel: myUpComingAppointments[itemIndex], - onTapped: isNeedToShowEmptyMessage - ? onAppointmentClick! - : () => - navigateWithName(context, AppRoutes.appointmentDetailView, - arguments: myUpComingAppointments[itemIndex]), + appointmentListModel: appointmentsVM.myUpComingAppointments[itemIndex], + onTapped: () { + if (appType == AppType.provider) { + onAppointmentClick!(appointmentsVM.myUpComingAppointments[itemIndex]); + } else { + navigateWithName(context, AppRoutes.appointmentDetailView, arguments: appointmentsVM.myUpComingAppointments[itemIndex]); + } + }, ), ); } + + @override + Widget build(BuildContext context) { + return Consumer(builder: (BuildContext context, AppointmentsVM model, Widget? child) { + if (model.state == ViewState.busy) { + return const Center(child: CircularProgressIndicator()); + } else { + if (AppState().currentAppType == AppType.provider) { + if (model.myUpComingAppointments.isEmpty) { + return "No Upcoming Appointment Available".toText().paddingAll(21); + } else { + return getCorouselWidget(AppState().currentAppType, model); + } + } else { + if (model.myUpComingAppointments.isEmpty) { + return CustomAddButton( + needsBorder: true, + bgColor: MyColors.white, + onTap: () => context.read().onNavbarTapped(0), + text: "Add New Appointment", + icon: Container( + height: 24, + width: 24, + decoration: const BoxDecoration(shape: BoxShape.circle, color: MyColors.darkTextColor), + child: const Icon(Icons.add, color: MyColors.white), + ), + ).padding(EdgeInsets.symmetric(vertical: 10, horizontal: 21)); + } else { + return getCorouselWidget(AppState().currentAppType, model); + } + } + } + }); + } + +// if (myUpComingAppointments.isEmpty) { +// if (isNeedToShowEmptyMessage) +// return "No Upcoming Appointment Available".toText().paddingAll(21); +// return CustomAddButton( +// needsBorder: true, +// bgColor: MyColors.white, +// onTap: () => context.read().onNavbarTapped(0), +// text: "Add New Appointment", +// icon: Container( +// height: 24, +// width: 24, +// decoration: const BoxDecoration( +// shape: BoxShape.circle, color: MyColors.darkTextColor), +// child: const Icon(Icons.add, color: MyColors.white), +// ), +// ).padding(EdgeInsets.symmetric(vertical: 10, horizontal: 21)); +// return Container( +// height: 86, +// child: Row( +// mainAxisAlignment: MainAxisAlignment.center, +// children: [ +// Container( +// height: 24, +// width: 24, +// decoration: BoxDecoration( +// shape: BoxShape.circle, color: MyColors.darkTextColor), +// child: Icon( +// Icons.add, +// color: MyColors.white, +// ), +// ), +// SizedBox(width: 10), +// "Add New Appointment".toText( +// fontSize: 15, +// isBold: true, +// color: MyColors.lightTextColor, +// ), +// ], +// ), +// ).onPress(() {}).toWhiteContainer( +// width: double.infinity, +// margin: EdgeInsets.symmetric(horizontal: 21, vertical: 10)); +// } +// return CarouselSlider.builder( +// options: CarouselOptions( +// height: 140, +// viewportFraction: 1.0, +// enlargeCenterPage: false, +// enableInfiniteScroll: false, +// ), +// itemCount: myUpComingAppointments.length, +// itemBuilder: (BuildContext context, int itemIndex, int pageViewIndex) => BuildAppointmentContainerForCustomer( +// isForHome: true, +// appointmentListModel: myUpComingAppointments[itemIndex], +// onTapped: isNeedToShowEmptyMessage ? onAppointmentClick! : () => navigateWithName(context, AppRoutes.appointmentDetailView, arguments: myUpComingAppointments[itemIndex]), +// ), +// ); } class BuildAppointmentContainerForCustomer extends StatelessWidget { final bool? isForHome; final AppointmentListModel? appointmentListModel; - final Function() onTapped; + final Function()? onTapped; - const BuildAppointmentContainerForCustomer({Key? key, - this.isForHome = false, - required this.onTapped, - required this.appointmentListModel}) - : super(key: key); + const BuildAppointmentContainerForCustomer({Key? key, this.isForHome = false, this.onTapped, required this.appointmentListModel}) : super(key: key); Widget showServices(String title, String icon, {bool isMoreText = false}) { return Row( @@ -121,18 +163,15 @@ class BuildAppointmentContainerForCustomer extends StatelessWidget { ); } - List buildServicesFromAppointment( - {required AppointmentListModel appointmentListModel}) { - if (appointmentListModel.appointmentServicesList == null || - appointmentListModel.appointmentServicesList!.isEmpty) { + List buildServicesFromAppointment({required AppointmentListModel appointmentListModel}) { + if (appointmentListModel.appointmentServicesList == null || appointmentListModel.appointmentServicesList!.isEmpty) { return [SizedBox()]; } if (appointmentListModel.appointmentServicesList!.length == 1) { return [ showServices( - appointmentListModel - .appointmentServicesList![0].providerServiceDescription, + appointmentListModel.appointmentServicesList![0].providerServiceDescription, MyAssets.modificationsIcon, ) ]; @@ -140,11 +179,7 @@ class BuildAppointmentContainerForCustomer extends StatelessWidget { List servicesList = List.generate( 2, - (index) => - showServices( - appointmentListModel - .appointmentServicesList![index].providerServiceDescription, - MyAssets.modificationsIcon), + (index) => showServices(appointmentListModel.appointmentServicesList![index].providerServiceDescription, MyAssets.modificationsIcon), ); if (appointmentListModel.appointmentServicesList!.length > 1) { @@ -187,16 +222,13 @@ class BuildAppointmentContainerForCustomer extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start, children: [ - (appointmentListModel!.providerName ?? "").toText( - color: MyColors.black, isBold: true, fontSize: 16), + (AppState().currentAppType == AppType.provider ? appointmentListModel!.customerName ?? "" : appointmentListModel!.branchName ?? "") + .toText(color: MyColors.black, isBold: true, fontSize: 16), Row( children: [ MyAssets.miniClock.buildSvg(height: 12), 2.width, - "${appointmentListModel!.duration ?? - ""} ${appointmentListModel!.appointmentDate! - .toFormattedDateWithoutTime()}" - .toText( + "${appointmentListModel!.duration ?? ""} ${appointmentListModel!.appointmentDate!.toFormattedDateWithoutTime()}".toText( color: MyColors.lightTextColor, fontSize: 12, ), @@ -222,9 +254,7 @@ class BuildAppointmentContainerForCustomer extends StatelessWidget { children: [ Expanded( child: Column( - children: buildServicesFromAppointment( - appointmentListModel: - appointmentListModel!), + children: buildServicesFromAppointment(appointmentListModel: appointmentListModel!), ), ), const Icon( @@ -238,9 +268,7 @@ class BuildAppointmentContainerForCustomer extends StatelessWidget { ], ), ], - ) - .onPress(onTapped) - .toWhiteContainer(width: double.infinity, allPading: 12), + ).onPress(onTapped!).toWhiteContainer(width: double.infinity, allPading: 12), ); } } diff --git a/lib/views/user/login_with_password_page.dart b/lib/views/user/login_with_password_page.dart index 01f279c..51835a4 100644 --- a/lib/views/user/login_with_password_page.dart +++ b/lib/views/user/login_with_password_page.dart @@ -46,13 +46,12 @@ class _LoginWithPasswordState extends State { void initState() { super.initState(); scheduleMicrotask(() { + userVM = Provider.of(context, listen: false); + context.read().getAvailBio(); if (AppState().currentAppType == AppType.provider) { phoneNum = "966530896018"; password = "Amir@1234"; } - userVM = Provider.of(context, listen: false); - context.read().getAvailBio(); - getCountryList(); }); diff --git a/pubspec.yaml b/pubspec.yaml index a85049c..d03f2c0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -47,7 +47,7 @@ dependencies: google_maps_flutter: ^2.1.1 geolocator: any # geocoding: ^2.1.0 - geocoding: ^2.1.1 + geocoding: ^3.0.0 # Auth