From 0d1fa2b1d79b1548897d58efbbd993ef7ce861fd Mon Sep 17 00:00:00 2001 From: Faiz Hashmi Date: Thu, 25 Jun 2026 16:32:16 +0300 Subject: [PATCH] fixing jira bugs --- lib/config/customer_routes.dart | 4 +- lib/main.dart | 3 - lib/views/branches/favourite_list_view.dart | 8 +- lib/views/branches/provider_profile_view.dart | 166 +++++++++++++++--- pubspec.yaml | 4 +- 5 files changed, 150 insertions(+), 35 deletions(-) diff --git a/lib/config/customer_routes.dart b/lib/config/customer_routes.dart index b3bdf20..d2f6ab8 100644 --- a/lib/config/customer_routes.dart +++ b/lib/config/customer_routes.dart @@ -2,6 +2,7 @@ import 'package:car_customer_app/views/branches/branch_detail_view.dart'; import 'package:car_customer_app/views/branches/favourite_list_view.dart'; import 'package:car_customer_app/views/branches/provider_profile_view.dart'; import 'package:mc_common_app/utils/enums.dart'; +import 'package:mc_common_app/views/advertisement/favourite_ads_view.dart'; import 'package:mc_common_app/views/appointments/appointment_detail_view.dart'; import 'package:mc_common_app/views/appointments/book_appointment_schedules_view.dart'; import 'package:mc_common_app/views/appointments/book_appointment_services_view.dart'; @@ -29,7 +30,8 @@ class CustomerAppRoutes { AppRoutes.branchSearchFilterPage: (context) => BranchesFilterView(), AppRoutes.appoinmentSearchFilterPage: (context) => AppointmentsFilterView(), AppRoutes.providerProfileView: (context) => ProviderProfileView(providerId: ModalRoute.of(context)!.settings.arguments as int), - AppRoutes.favoriteListView: (context) => FavoriteListView(), + AppRoutes.favoriteProvidersView: (context) => FavouriteProvidersView(), + AppRoutes.favouriteAdsView: (context) => const FavouriteAdsView(), }; } diff --git a/lib/main.dart b/lib/main.dart index 6d5f19d..685d69f 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -170,6 +170,3 @@ class MyApp extends StatelessWidget { ); } } - - - diff --git a/lib/views/branches/favourite_list_view.dart b/lib/views/branches/favourite_list_view.dart index 9362806..c35aa7e 100644 --- a/lib/views/branches/favourite_list_view.dart +++ b/lib/views/branches/favourite_list_view.dart @@ -18,14 +18,14 @@ import 'package:mc_common_app/widgets/common_widgets/provider_details_card.dart' import 'package:mc_common_app/widgets/extensions/extensions_widget.dart'; import 'package:provider/provider.dart'; -class FavoriteListView extends StatefulWidget { - const FavoriteListView({Key? key}) : super(key: key); +class FavouriteProvidersView extends StatefulWidget { + const FavouriteProvidersView({Key? key}) : super(key: key); @override - State createState() => _FavoriteListViewState(); + State createState() => _FavouriteProvidersViewState(); } -class _FavoriteListViewState extends State { +class _FavouriteProvidersViewState extends State { @override void initState() { scheduleMicrotask(() async => context.read().getMyFavoriteProviders()); diff --git a/lib/views/branches/provider_profile_view.dart b/lib/views/branches/provider_profile_view.dart index 09ae905..1ee0038 100644 --- a/lib/views/branches/provider_profile_view.dart +++ b/lib/views/branches/provider_profile_view.dart @@ -15,6 +15,7 @@ import 'package:mc_common_app/widgets/common_widgets/app_bar.dart'; import 'package:mc_common_app/widgets/common_widgets/branch_details_card.dart'; import 'package:mc_common_app/widgets/extensions/extensions_widget.dart'; import 'package:provider/provider.dart'; +import 'package:sizer/sizer.dart'; class ProviderProfileView extends StatefulWidget { final int providerId; @@ -49,30 +50,6 @@ class _ProviderProfileViewState extends State { return Scaffold( appBar: CustomAppBar( title: LocaleKeys.providerDetails.tr(), - actions: [ - Icon( - appointmentsVM.providerProfileModel!.isFavorite! ? Icons.favorite : Icons.favorite_border, - color: appointmentsVM.providerProfileModel!.isFavorite! ? MyColors.darkPrimaryColor : MyColors.black, - ).horPaddingMain().onPress( - () async { - if (appointmentsVM.providerProfileModel!.isFavorite!) { - bool status = await appointmentsVM.removeProviderFromFavorite(serviceProviderID: appointmentsVM.providerProfileModel!.id!, context: context); - if (status) { - appointmentsVM.providerProfileModel!.isFavorite = false; - appointmentsVM.getMyFavoriteProviders(); - setState(() {}); - } - } else { - bool status = await appointmentsVM.addProviderToFavorite(serviceProviderID: appointmentsVM.providerProfileModel!.id!, context: context); - - if (status) { - appointmentsVM.providerProfileModel!.isFavorite = true; - setState(() {}); - } - } - }, - ), - ], ), body: Container( width: double.infinity, @@ -84,7 +61,28 @@ class _ProviderProfileViewState extends State { Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Center(child: appointmentsVM.providerProfileModel!.profileImage.buildNetworkImage(height: 250, width: double.infinity, fit: BoxFit.cover)), + Stack( + children: [ + Center( + child: appointmentsVM.providerProfileModel!.profileImage.buildNetworkImage( + height: 250, + width: double.infinity, + fit: BoxFit.cover, + ), + ), + Positioned( + top: 10, + right: 10, + child: FavoriteProviderButton( + isFavorite: appointmentsVM.providerProfileModel!.isFavorite!, + serviceProviderID: appointmentsVM.providerProfileModel!.id!, + onToggle: () { + setState(() {}); + }, + ), + ), + ], + ), 12.height, if (appointmentsVM.providerProfileModel!.memberSince!.isNotEmpty) ...[ Row( @@ -166,3 +164,121 @@ class _ProviderProfileViewState extends State { ); } } + +class FavoriteProviderButton extends StatefulWidget { + final bool isFavorite; + final int serviceProviderID; + final VoidCallback onToggle; + + const FavoriteProviderButton({ + super.key, + required this.isFavorite, + required this.serviceProviderID, + required this.onToggle, + }); + + @override + State createState() => _FavoriteProviderButtonState(); +} + +class _FavoriteProviderButtonState extends State with SingleTickerProviderStateMixin { + bool isLoading = false; + late bool isFavorite; + late AnimationController _animationController; + late Animation _scaleAnimation; + + @override + void initState() { + super.initState(); + isFavorite = widget.isFavorite; + + _animationController = AnimationController( + duration: const Duration(milliseconds: 300), + vsync: this, + ); + + _scaleAnimation = Tween(begin: 1.0, end: 1.3).animate( + CurvedAnimation(parent: _animationController, curve: Curves.easeInOut), + ); + } + + @override + void dispose() { + _animationController.dispose(); + super.dispose(); + } + + Future toggleFavorite() async { + if (isLoading) return; + + setState(() { + isLoading = true; + }); + + _animationController.forward().then((_) => _animationController.reverse()); + + bool success; + if (isFavorite) { + success = await context.read().removeProviderFromFavorite(serviceProviderID: widget.serviceProviderID); + } else { + success = await context.read().addProviderToFavorite(serviceProviderID: widget.serviceProviderID); + } + + if (success) { + setState(() { + isFavorite = !isFavorite; + isLoading = false; + }); + context.read().providerProfileModel!.isFavorite = isFavorite; + if (isFavorite == false) { + context.read().getMyFavoriteProviders(); + } + widget.onToggle(); + } else { + setState(() { + isLoading = false; + }); + } + } + + @override + Widget build(BuildContext context) { + return GestureDetector( + onTap: toggleFavorite, + child: Container( + width: 8.6.w, + height: 8.6.w, + decoration: BoxDecoration( + color: Colors.white, + shape: BoxShape.circle, + boxShadow: [ + BoxShadow( + color: const Color(0xff000000).withOpacity(.07), + blurRadius: 8, + offset: const Offset(0, 2), + ), + ], + ), + child: Center( + child: isLoading + ? SizedBox( + width: 4.4.w, + height: 4.4.w, + child: const CircularProgressIndicator( + strokeWidth: 2, + valueColor: AlwaysStoppedAnimation(MyColors.darkPrimaryColor), + ), + ) + : ScaleTransition( + scale: _scaleAnimation, + child: Icon( + isFavorite ? Icons.favorite : Icons.favorite_border, + color: isFavorite ? Colors.red : MyColors.darkIconColor, + size: 5.5.w, + ), + ), + ), + ), + ); + } +} diff --git a/pubspec.yaml b/pubspec.yaml index 99b6eff..924cf08 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -36,10 +36,10 @@ dependencies: cupertino_icons: ^1.0.2 mc_common_app: -# path: /Volumes/Data/Projects/Flutter_Projects/car_common_app + path: /Volumes/Data/Projects/Flutter_Projects/mowater_apps/car_common_app # path: /Users/faizhashmi/Development/Projects/MyProjects/CloudSolutions/car_common_app # path: /Users/aamir/StudioProjects/car_common_app - path: C:/dev/Mawater/car_common_app +# path: C:/dev/Mawater/car_common_app dev_dependencies: