From 71030bf0fa55d9fe5f9e64a8783c6366af433edf Mon Sep 17 00:00:00 2001 From: Faiz Hashmi Date: Tue, 14 May 2024 18:12:32 +0300 Subject: [PATCH] Added Ads Filters and Appointments Filter --- lib/config/customer_routes.dart | 2 + lib/main.dart | 2 +- lib/views/dashboard/dashboard_page.dart | 162 +++++++++++++++--------- 3 files changed, 106 insertions(+), 60 deletions(-) diff --git a/lib/config/customer_routes.dart b/lib/config/customer_routes.dart index 99044e1..ead8a64 100644 --- a/lib/config/customer_routes.dart +++ b/lib/config/customer_routes.dart @@ -25,6 +25,7 @@ import 'package:mc_common_app/views/setting_options/setting_options_invite_frien import 'package:mc_common_app/views/setting_options/setting_options_language.dart'; import 'package:mc_common_app/views/chat/chat_view.dart'; import 'package:mc_common_app/views/branches/branches_filter_view.dart'; +import 'package:mc_common_app/views/appointments/appointments_filter_view.dart'; class CustomerAppRoutes { static final Map routes = { @@ -43,6 +44,7 @@ class CustomerAppRoutes { AppRoutes.paymentMethodsView: (context) => PaymentMethodsView(paymentType: ModalRoute.of(context)!.settings.arguments as PaymentTypes), AppRoutes.branchDetailPage: (context) => BranchDetailPage(branchDetailModel: ModalRoute.of(context)!.settings.arguments as BranchDetailModel), AppRoutes.branchSearchFilterPage: (context) => BranchesFilterView(), + AppRoutes.appoinmentSearchFilterPage: (context) => AppointmentsFilterView(), AppRoutes.providerProfilePage: (context) => ProviderProfilePage(providerId: ModalRoute.of(context)!.settings.arguments as int), AppRoutes.offersListPage: (context) => OfferListPage(offerListPageArguments: ModalRoute.of(context)!.settings.arguments as OfferListPageArguments), AppRoutes.createRequestPage: (context) => CreateRequestPage(), diff --git a/lib/main.dart b/lib/main.dart index abb5549..1e261f8 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -62,7 +62,7 @@ Future main() async { ), ChangeNotifierProvider( create: (_) => AppointmentsVM( - scheduleRepo: injector.get(), + appointmentRepo: injector.get(), commonServices: injector.get(), commonRepo: injector.get(), branchRepo: injector.get(), diff --git a/lib/views/dashboard/dashboard_page.dart b/lib/views/dashboard/dashboard_page.dart index 4a605a3..8d7225f 100644 --- a/lib/views/dashboard/dashboard_page.dart +++ b/lib/views/dashboard/dashboard_page.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'dart:developer'; import 'package:car_customer_app/views/dashboard/fragments/ads_fragment.dart'; import 'package:car_customer_app/views/dashboard/fragments/appointments_fragment.dart'; @@ -57,8 +58,9 @@ class _DashboardPageState extends State { if (appointmentsVM.myAppointments.isEmpty) { await appointmentsVM.getMyAppointments(); } + if (appointmentsVM.nearbyBranches.isEmpty) { - await appointmentsVM.getAllNearBranches(isFromRefresh: true); + await appointmentsVM.applyFilterOnBranches(index: 0); // to get all branches! } if (adVM.myAds.isEmpty) { @@ -99,7 +101,7 @@ class _DashboardPageState extends State { String getPageTitle(int index) { if (index == 0) { - return "Select Branch"; + return "Branches"; } if (index == 1) { return "Appointments"; @@ -120,54 +122,56 @@ class _DashboardPageState extends State { Widget build(BuildContext context) { DashboardVmCustomer dashboardVM = context.read(); bool isHomePage = dashboardVM.selectedNavbarBarIndex == 2; - return Scaffold( - appBar: CustomAppBar( - backgroundColor: null, - leadingWidth: 100, - title: getPageTitle(dashboardVM.selectedNavbarBarIndex), - profileImageUrl: MyAssets.bnCar, - isRemoveBackButton: true, - isDrawerEnabled: isHomePage ? true : false, - onTap: () { - if (isHomePage) { - navigateWithName(context, AppRoutes.settingOptionsLanguages); - } - }, - actions: [ - (isHomePage - ? Row( - children: [ - "${AppState().currentAppType}".toText(color: MyColors.darkTextColor).onPress( - () { - print("userId: ${AppState().getUser.data!.userInfo!.userId}"); - print("customerId: ${AppState().getUser.data!.userInfo!.customerId}"); - // context.read().buildHubConnection(); - }, - ), - 10.width, - MyAssets.notificationsBellIcon.buildSvg().onPress(() {}), - 15.width, - Icon(Icons.message, color: MyColors.darkTextColor).onPress( - () { - _onRefresh(); - }, - ), - ], - ) - : InkWell( - onTap: () async { - if (dashboardVM.selectedNavbarBarIndex == 3) { - await context.read().populateDataForAdFilter(); - navigateWithName(context, AppRoutes.adsFilterView); - } - if (dashboardVM.selectedNavbarBarIndex == 0) { - navigateWithName(context, AppRoutes.branchSearchFilterPage); - } - }, - child: Consumer( - builder: (BuildContext context, AppointmentsVM appointmentsVM, Widget? child) { - return appointmentsVM.branchFiltersCounter > 0 - ? Padding( + return WillPopScope( + onWillPop: () async => Future.value(false), + child: Scaffold( + appBar: CustomAppBar( + backgroundColor: null, + leadingWidth: 100, + title: getPageTitle(dashboardVM.selectedNavbarBarIndex), + profileImageUrl: MyAssets.bnCar, + isRemoveBackButton: true, + isDrawerEnabled: isHomePage ? true : false, + onTap: () { + if (isHomePage) { + navigateWithName(context, AppRoutes.settingOptionsLanguages); + } + }, + actions: [ + (isHomePage + ? Row( + children: [ + "${AppState().currentAppType}".toText(color: MyColors.darkTextColor).onPress( + () { + print("userId: ${AppState().getUser.data!.userInfo!.userId}"); + print("customerId: ${AppState().getUser.data!.userInfo!.customerId}"); + // context.read().buildHubConnection(); + }, + ), + 10.width, + MyAssets.notificationsBellIcon.buildSvg().onPress(() {}), + 15.width, + Icon(Icons.message, color: MyColors.darkTextColor) + ], + ) + : InkWell( + onTap: () async { + if (dashboardVM.selectedNavbarBarIndex == 0) { + navigateWithName(context, AppRoutes.branchSearchFilterPage); + } + if (dashboardVM.selectedNavbarBarIndex == 1) { + navigateWithName(context, AppRoutes.appoinmentSearchFilterPage); + } + if (dashboardVM.selectedNavbarBarIndex == 3) { + await context.read().populateDataForAdFilter(); + navigateWithName(context, AppRoutes.adsFilterView); + } + }, + child: Consumer2( + builder: (BuildContext context, AppointmentsVM appointmentsVM, AdVM adVM, Widget? child) { + if (dashboardVM.selectedNavbarBarIndex == 0) { + if (appointmentsVM.branchFiltersCounter > 0) { + return Padding( padding: const EdgeInsets.only(top: 20), child: Badge( largeSize: 15, @@ -176,16 +180,56 @@ class _DashboardPageState extends State { label: Text('${appointmentsVM.branchFiltersCounter}'), child: MyAssets.searchIcon.buildSvg(), ), - ) - : MyAssets.searchIcon.buildSvg(); - }, - ), - )) - .paddingOnly(right: 21) - ], + ); + } else { + return MyAssets.searchIcon.buildSvg(); + } + } + + if (dashboardVM.selectedNavbarBarIndex == 1) { + if (appointmentsVM.appointmentFiltersCounter > 0) { + return Padding( + padding: const EdgeInsets.only(top: 20), + child: Badge( + largeSize: 15, + smallSize: 20, + backgroundColor: MyColors.darkPrimaryColor, + label: Text('${appointmentsVM.appointmentFiltersCounter}'), + child: MyAssets.searchIcon.buildSvg(), + ), + ); + } else { + return MyAssets.searchIcon.buildSvg(); + } + } + + if (dashboardVM.selectedNavbarBarIndex == 3) { + if (adVM.adsFiltersCounter > 0) { + return Padding( + padding: const EdgeInsets.only(top: 20), + child: Badge( + largeSize: 15, + smallSize: 20, + backgroundColor: MyColors.darkPrimaryColor, + label: Text('${adVM.adsFiltersCounter}'), + child: MyAssets.searchIcon.buildSvg(), + ), + ); + } else { + return MyAssets.searchIcon.buildSvg(); + } + } + + return MyAssets.searchIcon.buildSvg(); + }, + ), + )) + .paddingOnly(right: 21) + ], + ), + bottomNavigationBar: CustomBottomNavbar(), + body: fragments[context.watch().selectedNavbarBarIndex], ), - bottomNavigationBar: CustomBottomNavbar(), - body: fragments[context.watch().selectedNavbarBarIndex], ); } }