|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:mc_common_app/classes/app_state.dart';
|
|
|
|
|
import 'package:mc_common_app/config/dependencies.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/models/general_models/m_response.dart';
|
|
|
|
|
import 'package:mc_common_app/theme/colors.dart';
|
|
|
|
|
import 'package:mc_common_app/utils/enums.dart';
|
|
|
|
|
import 'package:mc_common_app/utils/navigator.dart';
|
|
|
|
|
import 'package:mc_common_app/utils/utils.dart';
|
|
|
|
|
import 'package:mc_common_app/view_models/appointments_view_model.dart';
|
|
|
|
|
import 'package:mc_common_app/widgets/button/show_fill_button.dart';
|
|
|
|
|
import 'package:mc_common_app/widgets/common_widgets/app_bar.dart';
|
|
|
|
|
|
|
|
|
|
import '../../config/provider_routes.dart';
|
|
|
|
|
import '../dashboard/widget/appointment_slider_widget.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MergeAppointmentListPage extends StatelessWidget {
|
|
|
|
|
MergeAppointmentListPage({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Scaffold(
|
|
|
|
|
appBar: CustomAppBar(
|
|
|
|
|
title: LocaleKeys.selectAppointments.tr(),
|
|
|
|
|
),
|
|
|
|
|
body: SizedBox(
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
height: double.infinity,
|
|
|
|
|
child: Consumer(
|
|
|
|
|
builder: (BuildContext context, AppointmentsVM appointmentsVM,
|
|
|
|
|
Widget? child) {
|
|
|
|
|
return Column(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: (appointmentsVM.state == ViewState.busy)
|
|
|
|
|
? const Center(child: CircularProgressIndicator())
|
|
|
|
|
: ListView.separated(
|
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
|
return AppointmentSliderWidget(
|
|
|
|
|
appointmentListModel: appointmentsVM
|
|
|
|
|
.myFilteredAppointments2[appointmentsVM
|
|
|
|
|
.selectedAppointmentIndex]
|
|
|
|
|
.customerAppointmentList![index],
|
|
|
|
|
isNeedTotalPayment: true,
|
|
|
|
|
isSelectable: true,
|
|
|
|
|
isNeedToShowAppointmentStatus: true,
|
|
|
|
|
isNeedToShowMergeStatus: true,
|
|
|
|
|
onTap: () {
|
|
|
|
|
appointmentsVM
|
|
|
|
|
.updateCheckBoxInMergeRequest(index);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
separatorBuilder: (context, snapchat) {
|
|
|
|
|
return 21.height;
|
|
|
|
|
},
|
|
|
|
|
itemCount: appointmentsVM
|
|
|
|
|
.myFilteredAppointments2[
|
|
|
|
|
appointmentsVM.selectedAppointmentIndex]
|
|
|
|
|
.customerAppointmentList!
|
|
|
|
|
.length,
|
|
|
|
|
padding: const EdgeInsets.all(21),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
ShowFillButton(
|
|
|
|
|
title: LocaleKeys.mergeAppointments.tr(),
|
|
|
|
|
maxWidth: double.infinity,
|
|
|
|
|
margin: const EdgeInsets.all(21),
|
|
|
|
|
txtColor: appointmentsVM.inNeedToEnableMergeButton
|
|
|
|
|
? MyColors.white
|
|
|
|
|
: MyColors.black,
|
|
|
|
|
backgroundColor: appointmentsVM.inNeedToEnableMergeButton
|
|
|
|
|
? MyColors.primaryColor
|
|
|
|
|
: MyColors.greyButtonColor,
|
|
|
|
|
onPressed: () async {
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
List<int> appointmentIDs = [];
|
|
|
|
|
|
|
|
|
|
for (var element in appointmentsVM
|
|
|
|
|
.myFilteredAppointments2[
|
|
|
|
|
appointmentsVM.selectedAppointmentIndex]
|
|
|
|
|
.customerAppointmentList!) {
|
|
|
|
|
if (element.isSelected ?? false) {
|
|
|
|
|
appointmentIDs.add(element.id ?? 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Map<String, dynamic> map = {
|
|
|
|
|
"serviceProviderID": injector
|
|
|
|
|
.get<AppState>()
|
|
|
|
|
.getUser
|
|
|
|
|
.data
|
|
|
|
|
?.userInfo
|
|
|
|
|
?.providerId
|
|
|
|
|
.toString() ??
|
|
|
|
|
"0",
|
|
|
|
|
"serviceProviderBranchID": appointmentsVM
|
|
|
|
|
.myFilteredAppointments2[
|
|
|
|
|
appointmentsVM.selectedAppointmentIndex]
|
|
|
|
|
.branchId,
|
|
|
|
|
"serviceAppointmentIDs": appointmentIDs
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
MResponse response =
|
|
|
|
|
await appointmentsVM.createMergeAppointment(map);
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
if (response.messageStatus == 1) {
|
|
|
|
|
Utils.showToast(LocaleKeys.appointmentMergeSuccessfully.tr());
|
|
|
|
|
|
|
|
|
|
_updateAppointment(
|
|
|
|
|
context,
|
|
|
|
|
appointmentsVM
|
|
|
|
|
.myFilteredAppointments2[
|
|
|
|
|
appointmentsVM.selectedAppointmentIndex]
|
|
|
|
|
.branchId ??
|
|
|
|
|
0);
|
|
|
|
|
|
|
|
|
|
pop(context);
|
|
|
|
|
pop(context);
|
|
|
|
|
} else {
|
|
|
|
|
Utils.showToast(response.message.toString());
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
Utils.showToast(e.toString());
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> _updateAppointment(BuildContext context, int branchId) async {
|
|
|
|
|
await context.read<AppointmentsVM>().getMyAppointmentsForProvider({
|
|
|
|
|
"ServiceProviderID": injector
|
|
|
|
|
.get<AppState>()
|
|
|
|
|
.getUser
|
|
|
|
|
.data
|
|
|
|
|
?.userInfo
|
|
|
|
|
?.providerId
|
|
|
|
|
.toString() ??
|
|
|
|
|
"0",
|
|
|
|
|
"ProviderBranchID": branchId.toString(),
|
|
|
|
|
}, isNeedToRebuild: true);
|
|
|
|
|
}
|
|
|
|
|
}
|