diff --git a/lib/views/branch_management/services/services_list_page.dart b/lib/views/branch_management/services/services_list_page.dart index 12c96fb..557f4ec 100644 --- a/lib/views/branch_management/services/services_list_page.dart +++ b/lib/views/branch_management/services/services_list_page.dart @@ -76,7 +76,10 @@ class _ServicesListPageState extends State { ); context.read().applyFilterOnBranchServices(serviceStatusEnum: status); filteredServices = categoryData.services!.where((i) => i.serviceStatusEnum == status).toList(); - + int index = categoryData.services!.indexWhere((i) => i.serviceStatusEnum != ServiceStatusEnum.deactivated); + if (index != -1) { + isCategoryActive = true; + } screenState = ViewState.idle; setState(() {}); } @@ -132,38 +135,44 @@ class _ServicesListPageState extends State { ], ), ), - - // TODO: NEED TO CONFIRM CATEGORY DEACTIVATION FROM ZAHOOR - const Expanded( + Expanded( flex: 4, child: Column( children: [ - // LocaleKeys.active.tr().toText(fontSize: 16), - // 8.width, - // Container( - // width: 50, - // height: 30, - // decoration: BoxDecoration( - // color: isCategoryActive ? MyColors.darkPrimaryColor : MyColors.white, - // borderRadius: BorderRadius.circular(25.0), - // border: Border.all(color: MyColors.lightTextColor, width: 1), - // ), - // child: Transform.scale( - // scale: 0.8, - // child: CupertinoSwitch( - // activeColor: MyColors.darkPrimaryColor, - // trackColor: MyColors.white, - // thumbColor: MyColors.greyACColor, - // value: isCategoryActive, - // onChanged: (value) async { - // if (isEditDisabled) return; - // isCategoryActive = value; - // // isCategoryActive = await updateServiceStatus(context, value); - // setState(() {}); - // }, - // ), - // ), - // ), + LocaleKeys.active.tr().toText(fontSize: 16), + 8.width, + Container( + width: 50, + height: 30, + decoration: BoxDecoration( + color: isCategoryActive ? MyColors.darkPrimaryColor : MyColors.white, + borderRadius: BorderRadius.circular(25.0), + border: Border.all(color: MyColors.lightTextColor, width: 1), + ), + child: Transform.scale( + scale: 0.8, + child: CupertinoSwitch( + activeColor: MyColors.darkPrimaryColor, + trackColor: MyColors.white, + thumbColor: MyColors.greyACColor, + value: isCategoryActive, + onChanged: (value) async { + if (isEditDisabled) return; + final status = await updateCategoryStatus( + isCategoryActive: value, + categoryId: categoryData.id!, + branchId: int.parse(categoryData.branchId!), + ); + + if (status) { + isCategoryActive = value; + _onRefresh(value ? ServiceStatusEnum.pending : ServiceStatusEnum.deactivated); + } + setState(() {}); + }, + ), + ), + ), ], ), ), @@ -171,6 +180,19 @@ class _ServicesListPageState extends State { ).toWhiteContainer(width: double.infinity, allPading: 12); } + Future updateCategoryStatus({required bool isCategoryActive, required int categoryId, required int branchId}) async { + log("isCategoryActive: $isCategoryActive"); + final serviceVM = context.read(); + bool status = await serviceVM.updateCategoryStatus( + context: context, + serviceStatusEnum: isCategoryActive ? ServiceStatusEnum.approvedOrActive : ServiceStatusEnum.deactivated, + branchId: branchId, + categoryId: categoryId, + ); + + return status; + } + @override Widget build(BuildContext context) { categoryData = ModalRoute.of(context)!.settings.arguments as CategoryData; diff --git a/lib/views/dashboard/fragments/home_fragment.dart b/lib/views/dashboard/fragments/home_fragment.dart index 1c4241c..8fe4bb9 100644 --- a/lib/views/dashboard/fragments/home_fragment.dart +++ b/lib/views/dashboard/fragments/home_fragment.dart @@ -109,6 +109,7 @@ class HomeFragment extends StatelessWidget { isAdsFragment: false, adsList: adVM.myActiveAdsForHome, scrollPhysics: const NeverScrollableScrollPhysics(), + hasMoreData: adVM.isExploreAdsTapped ? adVM.hasMoreDataForExploreAds : adVM.hasMoreDataForMyAds, ), ], ) @@ -131,6 +132,7 @@ class HomeFragment extends StatelessWidget { adsList: adVM.exploreAds.length >= 3 ? adVM.exploreAds.take(3).toList() : adVM.exploreAds, isAdsFragment: false, scrollPhysics: const NeverScrollableScrollPhysics(), + hasMoreData: adVM.isExploreAdsTapped ? adVM.hasMoreDataForExploreAds : adVM.hasMoreDataForMyAds, ), ], )