From 7c8211b85c8dde6c863bab79ea7390ca529595a1 Mon Sep 17 00:00:00 2001 From: Faiz Hashmi Date: Thu, 22 Aug 2024 14:34:30 +0300 Subject: [PATCH] Fixed Few Things --- lib/config/customer_routes.dart | 4 +- .../components/branch_reviews_widget.dart | 17 +++++++- lib/views/branches/provider_profile_view.dart | 42 ++++++++++++++----- ...ashboard_page.dart => dashboard_view.dart} | 8 ++-- .../fragments/branches_fragment.dart | 13 ++---- .../dashboard/fragments/home_fragment.dart | 1 - 6 files changed, 57 insertions(+), 28 deletions(-) rename lib/views/dashboard/{dashboard_page.dart => dashboard_view.dart} (87%) diff --git a/lib/config/customer_routes.dart b/lib/config/customer_routes.dart index a01184a..f9f1ac9 100644 --- a/lib/config/customer_routes.dart +++ b/lib/config/customer_routes.dart @@ -6,7 +6,7 @@ import 'package:mc_common_app/views/appointments/book_appointment_services_view. import 'package:mc_common_app/views/appointments/book_appointments_item_view.dart'; import 'package:mc_common_app/views/appointments/pick_items_view.dart'; import 'package:mc_common_app/views/appointments/review_appointment_view.dart'; -import 'package:car_customer_app/views/dashboard/dashboard_page.dart'; +import 'package:car_customer_app/views/dashboard/dashboard_view.dart'; import 'package:flutter/cupertino.dart'; import 'package:mc_common_app/config/routes.dart'; import 'package:mc_common_app/models/advertisment_models/ad_details_model.dart'; @@ -29,7 +29,7 @@ import 'package:mc_common_app/views/appointments/appointments_filter_view.dart'; class CustomerAppRoutes { static final Map routes = { - AppRoutes.dashboard: (context) => DashboardPage(), + AppRoutes.dashboard: (context) => DashboardView(), AppRoutes.bookProviderAppView: (context) => BookProviderAppView(), AppRoutes.appointmentDetailView: (context) => AppointmentDetailView(appointmentListModel: ModalRoute.of(context)!.settings.arguments as AppointmentListModel), AppRoutes.bookAppointmenServicesView: (context) => BookAppointmentServicesView(), diff --git a/lib/views/branches/components/branch_reviews_widget.dart b/lib/views/branches/components/branch_reviews_widget.dart index 59aeeb4..7adde3a 100644 --- a/lib/views/branches/components/branch_reviews_widget.dart +++ b/lib/views/branches/components/branch_reviews_widget.dart @@ -4,6 +4,7 @@ import 'package:mc_common_app/extensions/string_extensions.dart'; import 'package:mc_common_app/generated/locale_keys.g.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:mc_common_app/extensions/int_extensions.dart'; +import 'package:mc_common_app/models/provider_branches_models/branch_review_model.dart'; import 'package:mc_common_app/theme/colors.dart'; import 'package:mc_common_app/utils/enums.dart'; import 'package:mc_common_app/view_models/appointments_view_model.dart'; @@ -58,18 +59,30 @@ class BranchReviewsWidget extends StatelessWidget { physics: NeverScrollableScrollPhysics(), shrinkWrap: true, itemBuilder: (context, index) { + BranchRatingModel rating = appointmentsVM.currentBranchReviews[index]; return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ 10.height, Row( children: [ - ("Mohammad Al Shafa - 5.0").toText(fontSize: 14, isBold: true), + ("${rating.title} - ${rating.ratNo}.0").toText(fontSize: 14, isBold: true), MyAssets.icStar.buildSvg(color: MyColors.darkPrimaryColor, height: 13).paddingOnly(left: 5, bottom: 2), ], ), 3.height, - "Some Reviews about the Provider from Customer".toText(fontSize: 12, color: MyColors.lightTextColor), + Row( + children: [ + Expanded( + flex: 9, + child: "${rating.review}".toText(fontSize: 12, color: MyColors.lightTextColor), + ), + Expanded( + flex: 3, + child: "-${rating.customerName ?? "Unknown"}".toText(fontSize: 2, color: MyColors.lightTextColor), + ), + ], + ), 10.height, ], ); diff --git a/lib/views/branches/provider_profile_view.dart b/lib/views/branches/provider_profile_view.dart index 9577818..2bf2f1d 100644 --- a/lib/views/branches/provider_profile_view.dart +++ b/lib/views/branches/provider_profile_view.dart @@ -1,5 +1,8 @@ +import 'dart:async'; import 'dart:developer'; +import 'package:mc_common_app/models/provider_branches_models/branch_detail_model.dart'; +import 'package:mc_common_app/utils/enums.dart'; import 'package:mc_common_app/view_models/appointments_view_model.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; @@ -28,17 +31,19 @@ class _ProviderProfileViewState extends State { @override void initState() { super.initState(); - context.read().getBranchAndServices(widget.providerId); + scheduleMicrotask(() async => context.read().getProviderProfileWithBranchesAndServices(widget.providerId)); } @override Widget build(BuildContext context) { return Consumer( builder: (BuildContext context, AppointmentsVM appointmentsVM, Widget? child) { - // log("appointmentsVM.providerProfileModel!.isFavorite: ${appointmentsVM.providerProfileModel!.isFavorite}"); - if (appointmentsVM.providerProfileModel == null) { + if (appointmentsVM.state == ViewState.busy) { return Scaffold( backgroundColor: MyColors.white, + appBar: CustomAppBar( + title: LocaleKeys.providerDetails.tr(), + ), body: Center( child: CircularProgressIndicator(), ), @@ -51,7 +56,23 @@ class _ProviderProfileViewState extends State { Icon( appointmentsVM.providerProfileModel!.isFavorite! ? Icons.favorite : Icons.favorite_border, color: appointmentsVM.providerProfileModel!.isFavorite! ? MyColors.darkPrimaryColor : MyColors.black, - ).horPaddingMain().onPress(() {}), + ).horPaddingMain().onPress(() async { + if (appointmentsVM.providerProfileModel!.isFavorite!) { + bool status = await appointmentsVM.removeProviderFromFavorite(serviceProviderID: appointmentsVM.providerProfileModel!.id!, context: context); + + if (status) { + appointmentsVM.providerProfileModel!.isFavorite = false; + setState(() {}); + } + } else { + bool status = await appointmentsVM.addProviderToFavorite(serviceProviderID: appointmentsVM.providerProfileModel!.id!, context: context); + + if (status) { + appointmentsVM.providerProfileModel!.isFavorite = true; + setState(() {}); + } + } + }), ], ), body: Container( @@ -90,16 +111,17 @@ class _ProviderProfileViewState extends State { ? Center(child: Text(LocaleKeys.no_branch.tr())) : ListView.separated( itemBuilder: (context, index) { + BranchDetailModel branchModel = appointmentsVM.providerProfileModel!.serviceProviderBranch![index]; return ProviderDetailsCard( onCardTapped: () { - navigateWithName(context, AppRoutes.branchDetailView, arguments: appointmentsVM.providerProfileModel!.serviceProviderBranch![index]); + navigateWithName(context, AppRoutes.branchDetailView, arguments: branchModel); }, providerImageUrl: MyAssets.bnCar, - title: appointmentsVM.providerProfileModel!.serviceProviderBranch![index].branchName ?? "", - providerLocation: appointmentsVM.providerProfileModel!.serviceProviderBranch![index].distanceKm.toString() + " KM", - providerName: appointmentsVM.providerProfileModel!.serviceProviderBranch![index].serviceProviderName ?? "", - providerRatings: "4.9", - services: appointmentsVM.providerProfileModel!.serviceProviderBranch![index].branchServices, + title: branchModel.branchName ?? "", + providerLocation: branchModel.distanceKm.toString() + " KM", + providerName: branchModel.serviceProviderName ?? "", + providerRatings: (branchModel.branchRateAvg ?? 0.0), + services: branchModel.branchServices, ); }, separatorBuilder: (context, index) { diff --git a/lib/views/dashboard/dashboard_page.dart b/lib/views/dashboard/dashboard_view.dart similarity index 87% rename from lib/views/dashboard/dashboard_page.dart rename to lib/views/dashboard/dashboard_view.dart index 0b17b54..0317624 100644 --- a/lib/views/dashboard/dashboard_page.dart +++ b/lib/views/dashboard/dashboard_view.dart @@ -11,14 +11,14 @@ import 'fragments/branches_fragment.dart'; import 'package:mc_common_app/views/common_fragments/ads_fragment.dart'; import 'package:mc_common_app/views/common_fragments/my_requests_fragment.dart'; -class DashboardPage extends StatefulWidget { - const DashboardPage({Key? key}) : super(key: key); +class DashboardView extends StatefulWidget { + const DashboardView({Key? key}) : super(key: key); @override - State createState() => _DashboardPageState(); + State createState() => _DashboardViewState(); } -class _DashboardPageState extends State { +class _DashboardViewState extends State { late DashboardVmCustomer dashboardVM; final GlobalKey _scaffoldKey = GlobalKey(); diff --git a/lib/views/dashboard/fragments/branches_fragment.dart b/lib/views/dashboard/fragments/branches_fragment.dart index cd8fba2..eb1fe39 100644 --- a/lib/views/dashboard/fragments/branches_fragment.dart +++ b/lib/views/dashboard/fragments/branches_fragment.dart @@ -63,7 +63,6 @@ class BranchesFragment extends StatelessWidget { }, child: Container( width: double.infinity, - height: MediaQuery.of(context).size.height / 1.37, child: appointmentsVM.state == ViewState.busy ? const Center( child: CircularProgressIndicator(), @@ -88,18 +87,14 @@ class BranchesFragment extends StatelessWidget { title: branchDetailModel.branchName ?? "", providerLocation: branchDetailModel.distanceKm.toString() + " KM", providerName: branchDetailModel.serviceProviderName ?? "", - providerRatings: "4.9", + providerRatings: branchDetailModel.branchRateAvg ?? 0.0, services: branchDetailModel.branchServices, ); }, - separatorBuilder: (context, index) { - return 12.height; - }, - padding: const EdgeInsets.all( - 12, - ), + separatorBuilder: (context, index) => 12.height, + padding: const EdgeInsets.all(12), ), - ), + ).paddingOnly(left: 10, right: 10), ), ), ], diff --git a/lib/views/dashboard/fragments/home_fragment.dart b/lib/views/dashboard/fragments/home_fragment.dart index 0ef5610..e3d8a8c 100644 --- a/lib/views/dashboard/fragments/home_fragment.dart +++ b/lib/views/dashboard/fragments/home_fragment.dart @@ -17,7 +17,6 @@ import 'package:mc_common_app/widgets/common_widgets/view_all_widget.dart'; import 'package:mc_common_app/widgets/extensions/extensions_widget.dart'; import 'package:provider/provider.dart'; import 'package:badges/badges.dart' as b; - import 'package:easy_localization/easy_localization.dart'; class HomeFragment extends StatelessWidget {