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.
356 lines
13 KiB
Dart
356 lines
13 KiB
Dart
import 'package:car_provider_app/config/provider_routes.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:mc_common_app/classes/consts.dart';
|
|
import 'package:mc_common_app/extensions/int_extensions.dart';
|
|
import 'package:mc_common_app/extensions/string_extensions.dart';
|
|
import 'package:mc_common_app/models/appointments_models/appointment_list_model.dart';
|
|
import 'package:mc_common_app/theme/colors.dart';
|
|
import 'package:mc_common_app/utils/navigator.dart';
|
|
import 'package:mc_common_app/widgets/extensions/extensions_widget.dart';
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
|
|
class AppointmentSliderWidget extends StatelessWidget {
|
|
AppointmentListModel appointmentListModel;
|
|
bool isNeedTotalPayment;
|
|
bool isNeedToShowItems;
|
|
bool isNeedToShowToMoreText;
|
|
bool isSelectable;
|
|
bool isNeedToShowAppointmentStatus;
|
|
bool isNeedToShowMergeStatus;
|
|
Function()? onTap;
|
|
|
|
AppointmentSliderWidget(
|
|
{required this.appointmentListModel,
|
|
required this.onTap,
|
|
this.isNeedTotalPayment = false,
|
|
this.isNeedToShowItems = false,
|
|
this.isNeedToShowToMoreText = true,
|
|
this.isSelectable = false,
|
|
this.isNeedToShowAppointmentStatus = false,
|
|
this.isNeedToShowMergeStatus = false,
|
|
Key? key})
|
|
: super(key: key);
|
|
|
|
List<Widget> buildServicesFromAppointment(
|
|
{required AppointmentListModel appointmentListModel}) {
|
|
if (appointmentListModel.appointmentServicesList == null ||
|
|
appointmentListModel.appointmentServicesList!.isEmpty) {
|
|
return [SizedBox()];
|
|
}
|
|
|
|
if (appointmentListModel.appointmentServicesList!.length == 1) {
|
|
List<Widget> itemsList = [];
|
|
if (isNeedToShowItems) {
|
|
itemsList = List.generate(
|
|
appointmentListModel
|
|
.appointmentServicesList?.first.serviceItems?.length ??
|
|
0,
|
|
(index) => (appointmentListModel.appointmentServicesList?.first
|
|
.serviceItems?[index].name ??
|
|
"")
|
|
.toString()
|
|
.toText(
|
|
color: MyColors.lightTextColor,
|
|
isBold: true,
|
|
),
|
|
);
|
|
}
|
|
return [
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
children: [
|
|
showServices(
|
|
appointmentListModel
|
|
.appointmentServicesList![0].providerServiceDescription,
|
|
MyAssets.modificationsIcon,
|
|
),
|
|
if (isNeedToShowItems) ...itemsList,
|
|
],
|
|
)
|
|
];
|
|
}
|
|
|
|
List<Widget> servicesList = List.generate(
|
|
isNeedToShowToMoreText
|
|
? 2
|
|
: appointmentListModel.appointmentServicesList?.length ?? 0,
|
|
(index) {
|
|
List<Widget> itemsList = [];
|
|
if (isNeedToShowItems) {
|
|
itemsList = List.generate(
|
|
appointmentListModel
|
|
.appointmentServicesList?[index].serviceItems?.length ??
|
|
0,
|
|
(mIndex) =>
|
|
(" - ${appointmentListModel.appointmentServicesList?[index].serviceItems?[mIndex].name ?? ""}")
|
|
.toString()
|
|
.toText(
|
|
color: MyColors.lightTextColor,
|
|
isBold: true,
|
|
),
|
|
);
|
|
}
|
|
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
showServices(
|
|
appointmentListModel
|
|
.appointmentServicesList![index].providerServiceDescription,
|
|
MyAssets.modificationsIcon),
|
|
if (isNeedToShowItems) ...itemsList,
|
|
],
|
|
).paddingOnly(bottom: 4);
|
|
},
|
|
);
|
|
|
|
if (isNeedToShowToMoreText &&
|
|
appointmentListModel.appointmentServicesList!.length > 1) {
|
|
servicesList.add(
|
|
showServices(
|
|
"+ ${appointmentListModel.appointmentServicesList!.length - 1} More",
|
|
"",
|
|
isMoreText: true,
|
|
),
|
|
);
|
|
}
|
|
return servicesList;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Row(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
if (isSelectable)
|
|
SizedBox(
|
|
child: const SizedBox(
|
|
width: 14,
|
|
height: 14,
|
|
).toContainer(
|
|
borderRadius: 24,
|
|
marginAll: 4,
|
|
paddingAll: 0,
|
|
backgroundColor: (appointmentListModel.isSelected ?? false)
|
|
? MyColors.primaryColor
|
|
: MyColors.greyButtonColor,
|
|
),
|
|
).toContainer(
|
|
borderRadius: 24,
|
|
isEnabledBorder: true,
|
|
paddingAll: 0,
|
|
borderWidget: 3,
|
|
borderColor: MyColors.primaryColor,
|
|
),
|
|
if (isSelectable) 12.width,
|
|
Expanded(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
if (isNeedToShowMergeStatus)
|
|
"Appointment Merged".toText(color: MyColors.white).toContainer(
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 6, vertical: 3),
|
|
borderRadius: 12,
|
|
backgroundColor: MyColors.greenColor,
|
|
),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
children: [
|
|
(appointmentListModel.branchName ?? "").toText(
|
|
fontSize: 12,
|
|
color: MyColors.darkTextColor,
|
|
isBold: true,
|
|
),
|
|
(appointmentListModel.customerName ?? "").toText(
|
|
color: MyColors.black, isBold: true, fontSize: 16),
|
|
Row(
|
|
children: [
|
|
"Phone:".toText(
|
|
color: MyColors.lightTextColor,
|
|
),
|
|
2.width,
|
|
appointmentListModel.customerMobileNum
|
|
.toString()
|
|
.toText(
|
|
fontSize: 12,
|
|
),
|
|
],
|
|
),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
"Appt. On:".toText(
|
|
color: MyColors.lightTextColor,
|
|
),
|
|
2.width,
|
|
Expanded(
|
|
child:
|
|
"${appointmentListModel.duration ?? ""} ${appointmentListModel.appointmentDate!.toFormattedDateWithoutTime()}"
|
|
.toText(
|
|
fontSize: 12,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
Row(
|
|
children: [
|
|
"Location: ".toText(
|
|
color: MyColors.lightTextColor,
|
|
),
|
|
2.width,
|
|
appointmentListModel.appointmentType
|
|
.toString()
|
|
.toText(
|
|
fontSize: 12,
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
if (!isNeedTotalPayment)
|
|
if (appointmentListModel.customerAppointmentList!.length >
|
|
1)
|
|
"${appointmentListModel.customerAppointmentList!.length - 1}+ Appointments"
|
|
.toText(
|
|
fontSize: 8,
|
|
)
|
|
.toContainer(
|
|
borderRadius: 15,
|
|
backgroundColor: MyColors.lightGreyEAColor,
|
|
padding: const EdgeInsets.symmetric(
|
|
vertical: 6,
|
|
horizontal: 12,
|
|
),
|
|
),
|
|
if (isNeedToShowAppointmentStatus)
|
|
(appointmentListModel.appointmentStatusEnum!
|
|
.getAppointmentNameFromEnum())
|
|
.toText(color: MyColors.white)
|
|
.toContainer(
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 6, vertical: 3),
|
|
borderRadius: 12,
|
|
backgroundColor: MyColors.primaryColor,
|
|
),
|
|
],
|
|
),
|
|
8.height,
|
|
Row(
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
children: [
|
|
Expanded(
|
|
child: Column(
|
|
children: [
|
|
...buildServicesFromAppointment(
|
|
appointmentListModel: appointmentListModel),
|
|
if (isNeedTotalPayment)
|
|
Column(
|
|
children: [
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
24.height,
|
|
"Total Amount".toText(
|
|
fontSize: 12,
|
|
color: MyColors.lightTextColor,
|
|
isBold: true,
|
|
),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
children: [
|
|
appointmentListModel.totalAmount
|
|
.toString()
|
|
.toText(fontSize: 16, isBold: true),
|
|
2.width,
|
|
"SAR:".toText(
|
|
color: MyColors.lightTextColor,
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
2.height,
|
|
"Remaining Amount".toText(
|
|
fontSize: 12,
|
|
color: MyColors.lightTextColor,
|
|
isBold: true,
|
|
),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
children: [
|
|
appointmentListModel.remainingAmount
|
|
.toString()
|
|
.toText(fontSize: 16, isBold: true),
|
|
2.width,
|
|
"SAR:".toText(
|
|
color: MyColors.lightTextColor,
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
],
|
|
)
|
|
],
|
|
),
|
|
),
|
|
if (!isNeedToShowItems)
|
|
const Icon(
|
|
Icons.arrow_forward,
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
)
|
|
],
|
|
).toWhiteContainer(width: double.infinity, allPading: 12, onTap: onTap);
|
|
}
|
|
|
|
double calculateTotalPrice() {
|
|
double totalServiceListPrice = 0;
|
|
appointmentListModel.appointmentServicesList!.forEach((servicesElement) {
|
|
servicesElement.serviceItems!.forEach((itemsElement) {
|
|
totalServiceListPrice += double.parse(itemsElement.price ?? "0");
|
|
});
|
|
});
|
|
|
|
return totalServiceListPrice;
|
|
}
|
|
|
|
Widget showServices(String title, String icon, {bool isMoreText = false}) {
|
|
return Row(
|
|
children: [
|
|
if (icon != "") ...[
|
|
SvgPicture.asset(icon),
|
|
8.width,
|
|
],
|
|
Flexible(
|
|
child: title.toText(
|
|
fontSize: 12,
|
|
isBold: true,
|
|
color: isMoreText ? MyColors.primaryColor : MyColors.black,
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|