From 8f43c4a3913a882bb1b72d14d35f0d2d4e33204b Mon Sep 17 00:00:00 2001 From: faizatflutter Date: Sun, 3 Nov 2024 02:51:59 +0300 Subject: [PATCH] small fixes from mbp --- .../add_new_service_appointment_page.dart | 20 +- .../branch/branch_detail_page.dart | 10 +- .../services/services_list_page.dart | 209 +++++++++++------- 3 files changed, 142 insertions(+), 97 deletions(-) diff --git a/lib/views/appoinments/add_new_service_appointment_page.dart b/lib/views/appoinments/add_new_service_appointment_page.dart index 5f5975e..112d6a8 100644 --- a/lib/views/appoinments/add_new_service_appointment_page.dart +++ b/lib/views/appoinments/add_new_service_appointment_page.dart @@ -80,7 +80,7 @@ class _AddNewServiceAppointmentPageState extends State( - builder: (context, model, _) { + builder: (context, serviceVm, _) { return Column( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ @@ -95,27 +95,27 @@ class _AddNewServiceAppointmentPageState extends State { int selectedTab = 0; ServiceStatusEnum selectedService = ServiceStatusEnum.approvedOrActive; + List filteredServices = []; + late CategoryData categoryData; + + ViewState screenState = ViewState.busy; + + @override + void initState() { + scheduleMicrotask(() async { + await _fetchServices(); + }); + super.initState(); + } + + Future _fetchServices() async { + categoryData.services = await context.read().fetchProviderServicesModelByCategoryIdAndBranchID( + branchID: categoryData.branchId.toString(), + categoryId: categoryData.id.toString(), + ); + filteredServices = categoryData.services!.where((i) => i.serviceStatus == ServiceStatusEnum.approvedOrActive.index + 1).toList(); + + screenState = ViewState.idle; + setState(() {}); + } + @override Widget build(BuildContext context) { - final categoryData = ModalRoute.of(context)!.settings.arguments as CategoryData; - List services = []; - if (selectedService == ServiceStatusEnum.approvedOrActive) { - services = categoryData.services!.where((i) => i.serviceStatus == ServiceStatusEnum.approvedOrActive.index + 1).toList(); - } else { - services = categoryData.services!.where((i) => i.serviceStatus != ServiceStatusEnum.approvedOrActive.index + 1).toList(); - } + categoryData = ModalRoute.of(context)!.settings.arguments as CategoryData; return Scaffold( appBar: CustomAppBar( @@ -97,8 +116,10 @@ class _ServicesListPageState extends State { selectedTab = value.id; if (selectedTab == 0) { selectedService = ServiceStatusEnum.approvedOrActive; + filteredServices = categoryData.services!.where((i) => i.serviceStatus == ServiceStatusEnum.approvedOrActive.index + 1).toList(); } else { selectedService = value.id.toServiceStatusEnum(); + filteredServices = categoryData.services!.where((i) => i.serviceStatus != ServiceStatusEnum.approvedOrActive.index + 1).toList(); } }); }, @@ -106,82 +127,106 @@ class _ServicesListPageState extends State { ), const SizedBox(height: 10), Expanded( - child: services.isEmpty - ? Center( - child: LocaleKeys.noItemsToShow.tr().toText(fontSize: 16, color: MyColors.lightTextColor), - ) - : ListView.separated( - itemBuilder: (context, index) { - return SizedBox( - width: double.infinity, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - if (services[index].serviceStatus == 1) ...[ - Utils.statusContainerChip(text: "Pending", chipColor: MyColors.adPendingStatusColor), - 5.height, - ], - Row( - children: [ - Expanded( - child: (services[index].serviceDescription ?? "").toText(fontSize: 16), - ), - if (services[index].serviceStatus != 1) ...[ - Padding( - padding: const EdgeInsets.all(4.0), - child: SvgPicture.asset( - MyAssets.icEdit, - width: 16, - height: 16, - ), - ).onPress(() { - navigateWithName(context, AppRoutes.createServices3, - arguments: CreateBranchModel( - branchId: categoryData.branchId ?? '', - branchName: categoryData.branchName ?? '', - categoryId: categoryData.id.toString(), - categoryName: categoryData.categoryName, - serviceProviderService: services[index], - isForEdit: true, - )); - }), - ] - ], - ), - const SizedBox(height: 4), - Row( - crossAxisAlignment: CrossAxisAlignment.end, - mainAxisAlignment: MainAxisAlignment.end, - children: [ - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, + child: RefreshIndicator( + onRefresh: () async { + screenState = ViewState.busy; + setState(() {}); + categoryData.services = await context.read().fetchProviderServicesModelByCategoryIdAndBranchID( + branchID: categoryData.branchId.toString(), + categoryId: categoryData.id.toString(), + ); + + if (selectedService == ServiceStatusEnum.approvedOrActive) { + filteredServices = categoryData.services!.where((i) => i.serviceStatus == ServiceStatusEnum.approvedOrActive.index + 1).toList(); + } else { + filteredServices = categoryData.services!.where((i) => i.serviceStatus != ServiceStatusEnum.approvedOrActive.index + 1).toList(); + } + screenState = ViewState.idle; + setState(() {}); + }, + child: screenState == ViewState.busy + ? const Center( + child: CircularProgressIndicator(), + ) + : filteredServices.isEmpty + ? Center( + child: LocaleKeys.noServicesAvailable.tr().toText(fontSize: 16, color: MyColors.lightTextColor), + ) + : ListView.separated( + itemBuilder: (context, index) { + return SizedBox( + width: double.infinity, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + if (filteredServices[index].serviceStatus == 1) ...[ + Utils.statusContainerChip(text: "Pending", chipColor: MyColors.adPendingStatusColor), + 5.height, + ], + Row( children: [ - const SizedBox(height: 4), - showItem('${LocaleKeys.availableforAppointment.tr()}:', (services[index].isAllowAppointment ?? false) ? LocaleKeys.yes.tr() : LocaleKeys.no.tr(), valueColor: Colors.green), - showItem('${LocaleKeys.allowingHomeService.tr()}:', (services[index].isAllowAppointmentHome ?? false) ? LocaleKeys.yes.tr() : LocaleKeys.no.tr(), valueColor: Colors.green), - if ((services[index].isAllowAppointmentHome ?? false)) ...[ - showItem('${LocaleKeys.homeServiceRange.tr()}:', services[index].customerLocationRange.toString()), - showItem('${LocaleKeys.chargesPerKM.tr()}:', services[index].rangePricePerKm.toString()), - ], + Expanded( + child: (filteredServices[index].serviceDescription ?? "").toText(fontSize: 16), + ), + if (filteredServices[index].serviceStatus != 1) ...[ + Padding( + padding: const EdgeInsets.all(4.0), + child: SvgPicture.asset( + MyAssets.icEdit, + width: 16, + height: 16, + ), + ).onPress(() { + navigateWithName(context, AppRoutes.createServices3, + arguments: CreateBranchModel( + branchId: categoryData.branchId ?? '', + branchName: categoryData.branchName ?? '', + categoryId: categoryData.id.toString(), + categoryName: categoryData.categoryName, + serviceProviderService: filteredServices[index], + isForEdit: true, + )); + }), + ] ], ), - ), - const Icon(Icons.arrow_forward_rounded, size: 20), - ], - ), - ], + const SizedBox(height: 4), + Row( + crossAxisAlignment: CrossAxisAlignment.end, + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const SizedBox(height: 4), + showItem('${LocaleKeys.availableforAppointment.tr()}:', (filteredServices[index].isAllowAppointment ?? false) ? LocaleKeys.yes.tr() : LocaleKeys.no.tr(), + valueColor: Colors.green), + showItem('${LocaleKeys.allowingHomeService.tr()}:', (filteredServices[index].isAllowAppointmentHome ?? false) ? LocaleKeys.yes.tr() : LocaleKeys.no.tr(), + valueColor: Colors.green), + if ((filteredServices[index].isAllowAppointmentHome ?? false)) ...[ + showItem('${LocaleKeys.homeServiceRange.tr()}:', filteredServices[index].customerLocationRange.toString()), + showItem('${LocaleKeys.chargesPerKM.tr()}:', filteredServices[index].rangePricePerKm.toString()), + ], + ], + ), + ), + const Icon(Icons.arrow_forward_rounded, size: 20), + ], + ), + ], + ), + ).toWhiteContainer(width: double.infinity, allPading: 12).onPress( + () => navigateWithName(context, AppRoutes.itemsList, arguments: filteredServices[index]), + ); + }, + separatorBuilder: (context, index) { + return const SizedBox(height: 12); + }, + padding: const EdgeInsets.only(left: 20, right: 20, bottom: 20, top: 10), + itemCount: filteredServices.length, ), - ).toWhiteContainer(width: double.infinity, allPading: 12).onPress( - () => navigateWithName(context, AppRoutes.itemsList, arguments: services[index]), - ); - }, - separatorBuilder: (context, index) { - return const SizedBox(height: 12); - }, - padding: const EdgeInsets.only(left: 20, right: 20, bottom: 20, top: 10), - itemCount: services.length, - ), + ), ), ], ),