diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index a4e4a3f..48ceaea 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -3,6 +3,7 @@ + diff --git a/lib/main.dart b/lib/main.dart index ed0cf99..112ef6b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -134,7 +134,7 @@ Future main() async { paymentService: injector.get(), paymentRepo: injector.get(), ), - ), + ), ChangeNotifierProvider( create: (_) => ShippingManagementVM( shippingRepo: injector.get(), diff --git a/lib/views/branch_management/branch/branch_detail_page.dart b/lib/views/branch_management/branch/branch_detail_page.dart index bbb81fc..5c1048c 100644 --- a/lib/views/branch_management/branch/branch_detail_page.dart +++ b/lib/views/branch_management/branch/branch_detail_page.dart @@ -60,9 +60,7 @@ class _BranchDetailPageState extends State { bool validation(BuildContext context) { bool isValid = false; - for (var element in context - .read() - .allProviderDealersList) { + for (var element in context.read().allProviderDealersList) { if (element.isBranchUser ?? false) { isValid = true; } @@ -102,7 +100,7 @@ class _BranchDetailPageState extends State { Widget buildFooterActionWidget(BuildContext context) { Widget actionWidget = const SizedBox(); - if (AppState().userType == UserType.providerDealer && widget.branchData.branchStatus == BranchStatusEnum.approvedOrActive) { + if ((AppState().userType == UserType.providerDealer || AppState().userType == UserType.providerIndividual) && widget.branchData.branchStatus == BranchStatusEnum.approvedOrActive) { actionWidget = ShowFillButton( title: LocaleKeys.assignDealerUser.tr(), maxWidth: double.infinity, @@ -174,47 +172,45 @@ class _BranchDetailPageState extends State { 8.width, Expanded( child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - isArabic ? serviceVM.categories[pIndex].categoryNameN.toString().toText(fontSize: 16): - serviceVM.categories[pIndex].categoryName.toString().toText(fontSize: 16), - ], - ), - 8.height, - Row( - mainAxisAlignment: MainAxisAlignment.end, - crossAxisAlignment: CrossAxisAlignment.end, - children: [ - Expanded( - child: ListView.builder( - itemBuilder: (context, index) { - return Container( - child: (EasyLocalization - .of(context) - ?.currentLocale - ?.countryCode == "SA" + isArabic + ? serviceVM.categories[pIndex].categoryNameN.toString().toText(fontSize: 14, maxLines: 2) + : serviceVM.categories[pIndex].categoryName.toString().toText(fontSize: 14, maxLines: 2), + ], + ), + 8.height, + Row( + mainAxisAlignment: MainAxisAlignment.end, + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + Expanded( + child: ListView.builder( + itemBuilder: (context, index) { + return Container( + child: (EasyLocalization.of(context)?.currentLocale?.countryCode == "SA" ? serviceVM.categories[pIndex].services![index].serviceDescriptionN.toString() : serviceVM.categories[pIndex].services![index].serviceDescription.toString()) - .toText( - fontSize: 12, - color: MyColors.lightTextColor, - ), - ); - }, - itemCount: serviceVM.categories[pIndex].services?.length, - physics: const NeverScrollableScrollPhysics(), - shrinkWrap: true, - padding: EdgeInsets.zero, - ), - ), - ], - ).withArrow(isArrowEnabled: true) + .toText( + fontSize: 12, + color: MyColors.lightTextColor, + ), + ); + }, + itemCount: serviceVM.categories[pIndex].services?.length, + physics: const NeverScrollableScrollPhysics(), + shrinkWrap: true, + padding: EdgeInsets.zero, + ), + ), ], - )), + ).withArrow(isArrowEnabled: true) + ], + )), ], ).toWhiteContainer(width: double.infinity, allPading: 12); } @@ -289,29 +285,27 @@ class _BranchDetailPageState extends State { 8.width, Expanded( child: LocaleKeys.setorEditBranchSchedule.tr().toText( - isUnderLine: true, - fontSize: 12, - color: Colors.white, - decorationColor: MyColors.white, - ), + isUnderLine: true, + fontSize: 12, + color: Colors.white, + decorationColor: MyColors.white, + ), ), ], ) .withArrow( - isArrowEnabled: true, - color: Colors.white, - arrowWidth: 16.16, - arrowHeight: 11.75, - ) + isArrowEnabled: true, + color: Colors.white, + arrowWidth: 16.16, + arrowHeight: 11.75, + ) .margin(right: 5), ).onPress(() { if (widget.branchData.branchStatus == BranchStatusEnum.pending || widget.branchData.branchStatus == BranchStatusEnum.rejected) { Utils.showToast(LocaleKeys.waitForBranchVerification.tr()); return; } - context - .read() - .currentSelectedBranchName = widget.branchData.branchName.toString(); + context.read().currentSelectedBranchName = widget.branchData.branchName.toString(); navigateWithName(context, AppRoutes.schedulesList, arguments: widget.branchData.id.toString()); }), 10.height, @@ -373,39 +367,38 @@ class _BranchDetailPageState extends State { const Center( child: CircularProgressIndicator(), ), - ] else - ...[ - ListView.separated( - itemBuilder: (context, pIndex) { - return buildServiceTileWidget(pIndex, serviceVM).onPress(() { - serviceVM.categories[pIndex].branchId = widget.branchData.id.toString(); - serviceVM.categories[pIndex].branchName = widget.branchData.branchName.toString(); - // CategoryData categoryData = serviceVM.categories[pIndex]; - serviceVM.applyFilterOnBranchServices(serviceStatusEnum: ServiceStatusEnum.approvedOrActive); + ] else ...[ + ListView.separated( + itemBuilder: (context, pIndex) { + return buildServiceTileWidget(pIndex, serviceVM).onPress(() { + serviceVM.categories[pIndex].branchId = widget.branchData.id.toString(); + serviceVM.categories[pIndex].branchName = widget.branchData.branchName.toString(); + // CategoryData categoryData = serviceVM.categories[pIndex]; + serviceVM.applyFilterOnBranchServices(serviceStatusEnum: ServiceStatusEnum.approvedOrActive); - CategoryData categoryData = CategoryData( - id: serviceVM.categories[pIndex].id, - branchId: serviceVM.categories[pIndex].branchId, - branchName: serviceVM.categories[pIndex].branchName, - categoryName: serviceVM.categories[pIndex].categoryName, - categoryNameN: serviceVM.categories[pIndex].categoryNameN, - serviceCategoryIconUrl: serviceVM.categories[pIndex].serviceCategoryIconUrl, - serviceCategoryImageUrl: serviceVM.categories[pIndex].serviceCategoryImageUrl, - services: [], - ); + CategoryData categoryData = CategoryData( + id: serviceVM.categories[pIndex].id, + branchId: serviceVM.categories[pIndex].branchId, + branchName: serviceVM.categories[pIndex].branchName, + categoryName: serviceVM.categories[pIndex].categoryName, + categoryNameN: serviceVM.categories[pIndex].categoryNameN, + serviceCategoryIconUrl: serviceVM.categories[pIndex].serviceCategoryIconUrl, + serviceCategoryImageUrl: serviceVM.categories[pIndex].serviceCategoryImageUrl, + services: [], + ); - navigateWithName(context, AppRoutes.servicesList, arguments: categoryData); - }); - }, - itemCount: serviceVM.categories.length, - physics: const NeverScrollableScrollPhysics(), - shrinkWrap: true, - padding: const EdgeInsets.all(20), - separatorBuilder: (BuildContext context, int index) { - return 12.height; - }, - ), - ], + navigateWithName(context, AppRoutes.servicesList, arguments: categoryData); + }); + }, + itemCount: serviceVM.categories.length, + physics: const NeverScrollableScrollPhysics(), + shrinkWrap: true, + padding: const EdgeInsets.all(20), + separatorBuilder: (BuildContext context, int index) { + return 12.height; + }, + ), + ], 12.height, ], ), diff --git a/lib/views/branch_management/branch/branch_list_page.dart b/lib/views/branch_management/branch/branch_list_page.dart index fa439f3..b212780 100644 --- a/lib/views/branch_management/branch/branch_list_page.dart +++ b/lib/views/branch_management/branch/branch_list_page.dart @@ -91,7 +91,8 @@ class BranchListPage extends StatelessWidget { return const Center(child: CircularProgressIndicator()); } else { List branches = []; - if (serviceVM.branches!.data != null) { + // Safe null check - don't use ! operator on serviceVM.branches + if (serviceVM.branches?.data?.serviceProviderBranch != null) { if (serviceVM.selectedBranchStatus == 3) { // 3 means active branch branches = serviceVM.branches!.data!.serviceProviderBranch!.where((element) => element.statusId == 3).toList(); diff --git a/lib/views/branch_management/services/create_services_page3.dart b/lib/views/branch_management/services/create_services_page3.dart index ce9a704..dedc708 100644 --- a/lib/views/branch_management/services/create_services_page3.dart +++ b/lib/views/branch_management/services/create_services_page3.dart @@ -137,6 +137,9 @@ class _CreateServicesPage3State extends State { if (status) { isServiceActive = value; + // Navigate back and pass the new service status + // Utils.showToast(LocaleKeys.serviceStatusUpdated.tr()); + Navigator.pop(context, value ? ServiceStatusEnum.approvedOrActive : ServiceStatusEnum.deactivated); } setState(() {}); }, diff --git a/lib/views/branch_management/services/services_list_page.dart b/lib/views/branch_management/services/services_list_page.dart index 827b04e..6286bfe 100644 --- a/lib/views/branch_management/services/services_list_page.dart +++ b/lib/views/branch_management/services/services_list_page.dart @@ -301,15 +301,24 @@ class _ServicesListPageState extends State { height: 16, ), ).onPress(() async { - navigateWithName(context, AppRoutes.createServices3, - arguments: CreateBranchModel( - branchId: categoryData.branchId ?? '', - branchName: categoryData.branchName ?? '', - categoryId: categoryData.id.toString(), - categoryName: categoryData.categoryName, - serviceProviderService: filteredServices[index], - isForEdit: true, - )); + final ServiceStatusEnum? newStatus = await Navigator.pushNamed( + context, + AppRoutes.createServices3, + arguments: CreateBranchModel( + branchId: categoryData.branchId ?? '', + branchName: categoryData.branchName ?? '', + categoryId: categoryData.id.toString(), + categoryName: categoryData.categoryName, + serviceProviderService: filteredServices[index], + isForEdit: true, + ), + ) as ServiceStatusEnum?; + + // If status was updated, switch to that filter and refresh + if (newStatus != null) { + selectedService = newStatus; + await _onRefresh(newStatus); + } }), ] ], diff --git a/lib/views/dashboard/dashboard_view.dart b/lib/views/dashboard/dashboard_view.dart index b243fa2..961db98 100644 --- a/lib/views/dashboard/dashboard_view.dart +++ b/lib/views/dashboard/dashboard_view.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'dart:developer'; import 'package:car_provider_app/views/branch_management/branch/branch_list_page.dart'; import 'package:flutter/material.dart'; +import 'package:mc_common_app/classes/app_state.dart'; import 'package:mc_common_app/utils/enums.dart'; import 'package:mc_common_app/view_models/dashboard_view_model_provider.dart'; import 'package:mc_common_app/views/common_fragments/requests_fragment.dart'; @@ -29,24 +30,43 @@ class _DashboardViewState extends State { log("widget.dashboardRouteEnum: ${widget.dashboardRouteEnum}"); super.initState(); dashboardVMProvider = Provider.of(context, listen: false); + + // Ensure selected index is valid for individual providers (no Requests tab) + if (AppState().userType != UserType.providerDealer) { + // For individuals, max index is 3 (Ads), so if selected is 4, set to Home (2) + if (dashboardVMProvider.selectedNavbarBarIndex >= 4) { + dashboardVMProvider.selectedNavbarBarIndex = 2; // Home + } + } + scheduleMicrotask(() => dashboardVMProvider.onRefresh(context, dashboardRouteEnum: widget.dashboardRouteEnum)); } @override Widget build(BuildContext context) { + // Build fragments list conditionally based on user type + // Individual providers should not have access to Requests List fragments = [ - const BranchListPage(), - const BranchAppointmentFragment(), - const HomeFragment(), - const AdsFragment(), - const MyRequestsFragment(), + const BranchListPage(), // 0 + const BranchAppointmentFragment(), // 1 + const HomeFragment(), // 2 + const AdsFragment(), // 3 + // Only Dealerships can access Special Requests + if (AppState().userType == UserType.providerDealer) + const MyRequestsFragment(), // 4 (only for dealerships) ]; + // Ensure the selected index is valid for the current fragments list + int validIndex = context.watch().selectedNavbarBarIndex; + if (validIndex >= fragments.length) { + validIndex = fragments.length - 1; // Default to last valid fragment + } + return PopScope( canPop: false, child: Scaffold( key: _scaffoldKey, - body: fragments[context.watch().selectedNavbarBarIndex], + body: fragments[validIndex], bottomNavigationBar: CustomBottomNavbar( onSelected: (index) { dashboardVMProvider.onNavbarTapped(index); diff --git a/lib/views/dashboard/fragments/branch_appointment_fragment.dart b/lib/views/dashboard/fragments/branch_appointment_fragment.dart index fed932d..0691ec3 100644 --- a/lib/views/dashboard/fragments/branch_appointment_fragment.dart +++ b/lib/views/dashboard/fragments/branch_appointment_fragment.dart @@ -37,7 +37,8 @@ class BranchAppointmentFragment extends StatelessWidget { return const Center(child: CircularProgressIndicator()); } else { List branches = []; - if (serviceVM.branches!.data != null) { + // Safe null check - don't use ! operator + if (serviceVM.branches?.data?.serviceProviderBranch != null) { branches = serviceVM.branches!.data!.serviceProviderBranch!.where((element) => 3 == element.statusId).toList(); } return RefreshIndicator(