You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
car_customer_app/lib/views/dashboard/fragments/home_fragment.dart

208 lines
9.3 KiB
Dart

import 'package:car_customer_app/views/dashboard/widgets/drawer_widget.dart';
import 'package:car_customer_app/views/dashboard/widgets/my_recent_branches_widget.dart';
import 'package:car_customer_app/views/dashboard/widgets/my_services_categories_widget.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:mc_common_app/config/routes.dart';
import 'package:mc_common_app/extensions/int_extensions.dart';
import 'package:mc_common_app/generated/locale_keys.g.dart';
import 'package:mc_common_app/utils/enums.dart';
import 'package:mc_common_app/utils/navigator.dart';
import 'package:mc_common_app/view_models/ad_view_model.dart';
import 'package:mc_common_app/view_models/appointments_view_model.dart';
import 'package:mc_common_app/view_models/dashboard_view_model_customer.dart';
import 'package:mc_common_app/views/advertisement/components/ads_list_widget.dart';
import 'package:mc_common_app/views/appointments/widgets/common_appointment_slider_widget.dart';
import 'package:mc_common_app/widgets/common_widgets/app_bar.dart';
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';
class HomeFragment extends StatelessWidget {
const HomeFragment({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
drawer: CustomDrawer(dashboardVM: context.watch<DashboardVmCustomer>()),
appBar: CustomAppBar(
isDrawerEnabled: true,
leadingWidth: 100,
onTap: () => navigateWithName(context, AppRoutes.settingOptionsMore),
actions: [
// IconButton(
// onPressed: () {},
// icon: const b.Badge(
// badgeContent: Text(
// '3',
// style: TextStyle(
// fontSize: 10,
// color: Colors.white,
// ),
// ),
// badgeStyle: b.BadgeStyle(
// badgeColor: MyColors.primaryColor,
// padding: EdgeInsets.all(5),
// ),
// child: Icon(Icons.notifications_active),
// ),
// ),
// 10.width,
],
),
body: SizedBox(
width: double.infinity,
height: double.infinity,
child: RefreshIndicator(
onRefresh: () async {
await context.read<DashboardVmCustomer>().onRefresh(context);
},
child: ListView(
children: [
16.height,
ViewAllWidget(
title: LocaleKeys.upcoming_appointment.tr().toUpperCase(),
subTitle: LocaleKeys.view_all.tr(),
onSubtitleTapped: () {
context.read<DashboardVmCustomer>().onNavbarTapped(1);
context.read<AppointmentsVM>().applyFilterOnAppointmentsVMForCustomers(appointmentStatusEnum: AppointmentStatusEnum.allAppointments);
},
).horPaddingMain(),
CommonAppointmentSliderWidget()
.toWhiteContainer(
width: double.infinity,
backgroundColor: Colors.transparent,
)
.margin(left: 21, right: 21),
// SERVICES SECTION
14.height,
Consumer(
builder: (BuildContext context, AppointmentsVM appointmentVM, Widget? child) {
if (appointmentVM.state == ViewState.busy) {
return Center(child: CircularProgressIndicator());
}
if (appointmentVM.branchesCategoriesFilterOptions.isNotEmpty) {
return Column(
children: [
ViewAllWidget(
title: LocaleKeys.services.tr().toUpperCase(),
subTitle: '',
onSubtitleTapped: () {},
).horPaddingMain(),
MyServicesCategoriesWidget(homeCategories: appointmentVM.branchesCategoriesFilterOptions).horPaddingMain()
],
);
}
return SizedBox();
},
),
// NEARBY BRANCHES SECTION
// 7.height,
// Consumer(
// builder: (BuildContext context, AppointmentsVM appointmentVM, Widget? child) {
// if (appointmentVM.state == ViewState.busy) {
// return Center(child: CircularProgressIndicator());
// }
//
// if (appointmentVM.myRecentBranches.isNotEmpty) {
// return Column(
// children: [
// ViewAllWidget(
// title: LocaleKeys.myRecentBranches.tr().toUpperCase(),
// subTitle: '',
// onSubtitleTapped: () {
// // context.read<DashboardVmCustomer>().onNavbarTapped(0);
// // context.read<AppointmentsVM>().applyFilterOnBranches(index: 0);
// },
// ).horPaddingMain(),
// MyRecentBranchesWidget(nearbyBranches: appointmentVM.myRecentBranches).horPaddingMain(),
// ],
// );
// }
// if (appointmentVM.nearbyBranches.isNotEmpty) {
// return Column(
// children: [
// ViewAllWidget(
// title: LocaleKeys.myNearbyBranches.tr().toUpperCase(),
// subTitle: LocaleKeys.view_all.tr(),
// onSubtitleTapped: () {
// context.read<DashboardVmCustomer>().onNavbarTapped(0);
// context.read<AppointmentsVM>().applyFilterOnBranches(index: 0);
// },
// ).horPaddingMain(),
// MyRecentBranchesWidget(nearbyBranches: appointmentVM.nearbyBranches).horPaddingMain(),
// ],
// );
// }
//
// return SizedBox();
// },
// ),
// ADS SECTION
Consumer(
builder: (BuildContext context, AdVM adVM, Widget? child) {
if (adVM.state == ViewState.busy) {
return Center(child: CircularProgressIndicator());
}
return Column(
children: [
if (adVM.myActiveAdsForHome.isNotEmpty) ...[
Column(
children: [
15.height,
ViewAllWidget(
title: LocaleKeys.my_active_Ads.tr().toUpperCase(),
subTitle: LocaleKeys.view_all.tr(),
onSubtitleTapped: () {
context.read<DashboardVmCustomer>().onNavbarTapped(3);
context.read<AdVM>().updateIsExploreAds(false);
}).horPaddingMain(),
AdsListWidget(
shouldShowAdStatus: true,
isAdsFragment: false,
adsList: adVM.myActiveAdsForHome,
scrollPhysics: NeverScrollableScrollPhysics(),
hasMoreData: adVM.isExploreAdsTapped ? adVM.hasMoreDataForExploreAds : adVM.hasMoreDataForMyAds,
),
],
)
],
if (adVM.exploreAds.isNotEmpty) ...[
Column(
children: [
15.height,
ViewAllWidget(
title: LocaleKeys.myRecommendedAds.tr().toUpperCase(),
subTitle: LocaleKeys.view_all.tr(),
onSubtitleTapped: () {
context.read<DashboardVmCustomer>().onNavbarTapped(3);
context.read<AdVM>().updateIsExploreAds(true);
context.read<AdVM>().applyFilterOnExploreAds(vehicleBrandId: 0);
},
).horPaddingMain(),
AdsListWidget(
shouldShowAdStatus: false,
adsList: adVM.exploreAds.length >= 3 ? adVM.exploreAds.take(3).toList() : adVM.exploreAds,
isAdsFragment: false,
scrollPhysics: NeverScrollableScrollPhysics(),
hasMoreData: adVM.isExploreAdsTapped ? adVM.hasMoreDataForExploreAds : adVM.hasMoreDataForMyAds,
),
],
)
]
],
);
},
),
20.height,
],
),
),
),
);
}
}