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.
268 lines
12 KiB
Dart
268 lines
12 KiB
Dart
import 'dart:async';
|
|
import 'package:car_customer_app/views/branches/components/branch_reviews_widget.dart';
|
|
import 'package:car_customer_app/views/branches/components/items_list_sheet.dart';
|
|
import 'package:mc_common_app/utils/utils.dart';
|
|
import 'package:mc_common_app/view_models/appointments_view_model.dart';
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:mc_common_app/classes/consts.dart';
|
|
import 'package:mc_common_app/config/routes.dart';
|
|
import 'package:mc_common_app/extensions/int_extensions.dart';
|
|
import 'package:mc_common_app/extensions/string_extensions.dart';
|
|
import 'package:mc_common_app/generated/locale_keys.g.dart';
|
|
import 'package:mc_common_app/models/provider_branches_models/branch_detail_model.dart';
|
|
import 'package:mc_common_app/theme/colors.dart';
|
|
import 'package:mc_common_app/utils/navigator.dart';
|
|
import 'package:mc_common_app/views/advertisement/components/ads_images_corousel_widget.dart';
|
|
import 'package:mc_common_app/widgets/bottom_sheet.dart';
|
|
import 'package:mc_common_app/widgets/button/show_fill_button.dart';
|
|
import 'package:mc_common_app/widgets/common_widgets/app_bar.dart';
|
|
import 'package:mc_common_app/widgets/extensions/extensions_widget.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
class BranchDetailView extends StatefulWidget {
|
|
final BranchDetailModel branchDetailModel;
|
|
|
|
BranchDetailView({required this.branchDetailModel});
|
|
|
|
@override
|
|
State<BranchDetailView> createState() => _BranchDetailViewState();
|
|
}
|
|
|
|
class _BranchDetailViewState extends State<BranchDetailView> {
|
|
late AppointmentsVM appointmentsVM;
|
|
|
|
@override
|
|
void initState() {
|
|
appointmentsVM = context.read<AppointmentsVM>();
|
|
super.initState();
|
|
if (widget.branchDetailModel.branchServices!.length > 0) widget.branchDetailModel.branchServices?.first.isExpandedOrSelected = true;
|
|
getBranchReviews();
|
|
}
|
|
|
|
Future<void> getBranchReviews() async {
|
|
scheduleMicrotask(() async {
|
|
await appointmentsVM.getReviewsByBranchId(serviceProviderBranchID: widget.branchDetailModel.id!);
|
|
});
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
appointmentsVM.resetCurrentBranchRatings();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: CustomAppBar(
|
|
title: LocaleKeys.branchDetail.tr(),
|
|
actions: [
|
|
// Padding(
|
|
// padding: EdgeInsets.only(top: 8, bottom: 8, right: 21),
|
|
// child: const Icon(Icons.messenger_outline_rounded, color: Colors.black, size: 18).toContainer(
|
|
// borderRadius: 100,
|
|
// borderColor: MyColors.lightGreyEFColor,
|
|
// isEnabledBorder: true,
|
|
// ),
|
|
// ).onPress(() {})
|
|
],
|
|
),
|
|
body: Column(
|
|
children: [
|
|
Expanded(
|
|
child: SingleChildScrollView(
|
|
child: Container(
|
|
width: double.infinity,
|
|
padding: EdgeInsets.all(21),
|
|
child: Column(
|
|
children: [
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
ImagesCorouselWidget(imagesList: widget.branchDetailModel.branchImages ?? []),
|
|
12.height,
|
|
"${widget.branchDetailModel.branchName} | ${widget.branchDetailModel.serviceProviderName}".toString().toText(
|
|
fontSize: 16,
|
|
isBold: true,
|
|
),
|
|
Row(
|
|
children: [
|
|
(LocaleKeys.location.tr() + ":").toText(color: MyColors.lightTextColor, fontSize: 12),
|
|
4.width,
|
|
(widget.branchDetailModel.distanceKm.toString() + " km").toText(fontSize: 12, isBold: true),
|
|
],
|
|
),
|
|
Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
(LocaleKeys.time.tr() + ":").toText(color: MyColors.lightTextColor, fontSize: 12),
|
|
4.width,
|
|
Flexible(
|
|
child: "${widget.branchDetailModel.openTime} - ${widget.branchDetailModel.closeTime}".toText(fontSize: 12, isBold: true),
|
|
)
|
|
],
|
|
),
|
|
2.height,
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
if ((widget.branchDetailModel.latitude != null && widget.branchDetailModel.latitude!.isNotEmpty) && (widget.branchDetailModel.longitude != null && widget.branchDetailModel.longitude!.isNotEmpty)) ...[
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
LocaleKeys.openMapLocation.tr().toText(
|
|
fontSize: 12,
|
|
isBold: true,
|
|
color: MyColors.primaryColor,
|
|
isUnderLine: true,
|
|
),
|
|
4.width,
|
|
Image.asset(
|
|
MyAssets.icRightUpPng,
|
|
height: 6,
|
|
width: 6,
|
|
color: MyColors.primaryColor,
|
|
),
|
|
],
|
|
).padding(EdgeInsets.symmetric(vertical: 6, horizontal: 2)).onPress(() async {
|
|
double latitude, longitude = 0.0;
|
|
|
|
latitude = double.parse(widget.branchDetailModel.latitude!);
|
|
longitude = double.parse(widget.branchDetailModel.longitude!);
|
|
await Utils.openLocationInMaps(latitude: latitude, longitude: longitude);
|
|
}),
|
|
] else ...[
|
|
SizedBox(),
|
|
],
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
LocaleKeys.providerProfile.tr().toText(
|
|
fontSize: 12,
|
|
isBold: true,
|
|
color: MyColors.primaryColor,
|
|
isUnderLine: true,
|
|
),
|
|
2.width,
|
|
Icon(
|
|
Icons.arrow_forward,
|
|
size: 12,
|
|
color: MyColors.primaryColor,
|
|
),
|
|
],
|
|
).padding(EdgeInsets.symmetric(vertical: 6, horizontal: 2)).onPress(() => navigateWithName(context, AppRoutes.providerProfileView, arguments: widget.branchDetailModel.serviceProviderId)),
|
|
],
|
|
),
|
|
20.height,
|
|
LocaleKeys.servicesOffer.tr().toText(
|
|
fontSize: 16,
|
|
color: MyColors.lightTextColor,
|
|
isBold: true,
|
|
),
|
|
if (widget.branchDetailModel.branchServices!.length == 0)
|
|
LocaleKeys.noServicesAvailable.tr().toText(
|
|
fontSize: 12,
|
|
color: MyColors.lightTextColor,
|
|
isBold: true,
|
|
),
|
|
buildServicesList(),
|
|
],
|
|
).toWhiteContainer(width: double.infinity, allPading: 12),
|
|
10.height,
|
|
BranchReviewsWidget(branchRateAvg: widget.branchDetailModel.branchRateAvg ?? 0.0),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
ShowFillButton(
|
|
maxHeight: 55,
|
|
isDisabled: widget.branchDetailModel.branchServices!.length == 0,
|
|
title: LocaleKeys.bookAppointment.tr(),
|
|
margin: EdgeInsets.all(12),
|
|
maxWidth: double.infinity,
|
|
onPressed: () {
|
|
if (widget.branchDetailModel.branchServices!.length == 0) {
|
|
Utils.showToast(LocaleKeys.noServicesAvailable.tr());
|
|
return;
|
|
}
|
|
navigateWithName(context, AppRoutes.bookAppointmenServicesView);
|
|
context.read<AppointmentsVM>().updateSelectedBranch(widget.branchDetailModel);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget buildServicesList() {
|
|
return ListView.separated(
|
|
itemBuilder: (context, index) {
|
|
return ExpansionTile(
|
|
tilePadding: EdgeInsets.zero,
|
|
title: (widget.branchDetailModel.branchServices![index].serviceDescription ?? "").toText(fontSize: 16),
|
|
children: [
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
showItem(LocaleKeys.allowingHomeService.tr() + " :", (widget.branchDetailModel.branchServices![index].isAllowAppointment ?? false) ? LocaleKeys.yes.tr() : LocaleKeys.no.tr(), valueColor: Colors.green),
|
|
if ((widget.branchDetailModel.branchServices![index].isAllowAppointment ?? false)) ...[
|
|
showItem(LocaleKeys.homeServiceRange.tr() + " :", widget.branchDetailModel.branchServices![index].customerLocationRange.toString() + "KM"),
|
|
showItem(LocaleKeys.chargesPerKM.tr() + " :", widget.branchDetailModel.branchServices![index].customerLocationRange.toString() + LocaleKeys.sar.tr()),
|
|
],
|
|
8.height,
|
|
((widget.branchDetailModel.branchServices![index].itemsCount != null && widget.branchDetailModel.branchServices![index].itemsCount! > 0)
|
|
? widget.branchDetailModel.branchServices![index].itemsCount.toString() + " items"
|
|
: "No" + " items")
|
|
.toText(
|
|
fontSize: 12,
|
|
isBold: true,
|
|
color: MyColors.primaryColor,
|
|
isUnderLine: true,
|
|
),
|
|
20.height,
|
|
],
|
|
).onPress(() {
|
|
if (widget.branchDetailModel.branchServices![index].itemsCount != null && widget.branchDetailModel.branchServices![index].itemsCount! > 0) {
|
|
showMyBottomSheet(context, child: ItemsListSheet(widget.branchDetailModel.branchServices![index].serviceProviderServiceId ?? 0));
|
|
}
|
|
}),
|
|
],
|
|
onExpansionChanged: (value) {
|
|
setState(() {
|
|
widget.branchDetailModel.branchServices![index].isExpandedOrSelected = value;
|
|
});
|
|
},
|
|
backgroundColor: Colors.transparent,
|
|
collapsedBackgroundColor: Colors.transparent,
|
|
initiallyExpanded: widget.branchDetailModel.branchServices![index].isExpandedOrSelected,
|
|
trailing: widget.branchDetailModel.branchServices![index].isExpandedOrSelected ? Icon(Icons.keyboard_arrow_up) : Icon(Icons.keyboard_arrow_down),
|
|
);
|
|
},
|
|
separatorBuilder: (context, index) {
|
|
return Divider(
|
|
height: 1,
|
|
);
|
|
},
|
|
itemCount: widget.branchDetailModel.branchServices!.length,
|
|
physics: NeverScrollableScrollPhysics(),
|
|
shrinkWrap: true,
|
|
);
|
|
}
|
|
|
|
Widget showItem(String item, String value, {Color valueColor = Colors.black}) {
|
|
return Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
children: [
|
|
item.toText(fontSize: 12, color: MyColors.lightTextColor),
|
|
4.width,
|
|
value.toText(fontSize: 12, color: valueColor),
|
|
],
|
|
);
|
|
}
|
|
}
|