|
|
|
@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
|
|
|
|
import 'package:car_provider_app/view_models/service_view_model.dart';
|
|
|
|
import 'package:car_provider_app/view_models/service_view_model.dart';
|
|
|
|
import 'package:car_provider_app/views/appoinments/widget/select_items_sheet.dart';
|
|
|
|
import 'package:car_provider_app/views/appoinments/widget/select_items_sheet.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
@ -25,22 +27,37 @@ import '../../generated/locale_keys.g.dart';
|
|
|
|
import '../dashboard/widget/appointment_slider_widget.dart';
|
|
|
|
import '../dashboard/widget/appointment_slider_widget.dart';
|
|
|
|
import '../settings/schedule/widgets/chips_picker_item.dart';
|
|
|
|
import '../settings/schedule/widgets/chips_picker_item.dart';
|
|
|
|
|
|
|
|
|
|
|
|
class AddNewServiceAppointmentPage extends StatelessWidget {
|
|
|
|
class AddNewServiceAppointmentPage extends StatefulWidget {
|
|
|
|
AppointmentListModel appointmentListModel;
|
|
|
|
AppointmentListModel appointmentListModel;
|
|
|
|
|
|
|
|
|
|
|
|
AddNewServiceAppointmentPage(this.appointmentListModel, {Key? key})
|
|
|
|
AddNewServiceAppointmentPage(this.appointmentListModel, {Key? key}) : super(key: key);
|
|
|
|
: super(key: key);
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
|
|
State<AddNewServiceAppointmentPage> createState() => _AddNewServiceAppointmentPageState();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class _AddNewServiceAppointmentPageState extends State<AddNewServiceAppointmentPage> {
|
|
|
|
DropValue? category;
|
|
|
|
DropValue? category;
|
|
|
|
|
|
|
|
|
|
|
|
DropValue? service;
|
|
|
|
DropValue? service;
|
|
|
|
|
|
|
|
|
|
|
|
List<ItemData> selectedList = [];
|
|
|
|
List<ItemData> selectedList = [];
|
|
|
|
|
|
|
|
|
|
|
|
List<PickerItem>? pickedItems;
|
|
|
|
List<PickerItem>? pickedItems;
|
|
|
|
|
|
|
|
ServiceVM? serviceVM;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
|
|
void initState() {
|
|
|
|
|
|
|
|
// TODO: implement initState
|
|
|
|
|
|
|
|
super.initState();
|
|
|
|
|
|
|
|
scheduleMicrotask(() {
|
|
|
|
|
|
|
|
serviceVM = context.read<ServiceVM>();
|
|
|
|
|
|
|
|
serviceVM!.fetchBranchCategory(EasyLocalization.of(context)?.currentLocale?.countryCode ?? "SA");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
ServiceVM serviceVM = context.read<ServiceVM>();
|
|
|
|
|
|
|
|
serviceVM.fetchBranchCategory(
|
|
|
|
|
|
|
|
EasyLocalization.of(context)?.currentLocale?.countryCode ?? "SA");
|
|
|
|
|
|
|
|
return Scaffold(
|
|
|
|
return Scaffold(
|
|
|
|
appBar: const CustomAppBar(
|
|
|
|
appBar: const CustomAppBar(
|
|
|
|
title: "Add Service",
|
|
|
|
title: "Add Service",
|
|
|
|
@ -50,7 +67,7 @@ class AddNewServiceAppointmentPage extends StatelessWidget {
|
|
|
|
child: Column(
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
children: [
|
|
|
|
AppointmentSliderWidget(
|
|
|
|
AppointmentSliderWidget(
|
|
|
|
appointmentListModel: appointmentListModel,
|
|
|
|
appointmentListModel: widget.appointmentListModel,
|
|
|
|
isNeedTotalPayment: true,
|
|
|
|
isNeedTotalPayment: true,
|
|
|
|
isNeedToShowItems: true,
|
|
|
|
isNeedToShowItems: true,
|
|
|
|
isNeedToShowToMoreText: false,
|
|
|
|
isNeedToShowToMoreText: false,
|
|
|
|
@ -79,15 +96,11 @@ class AddNewServiceAppointmentPage extends StatelessWidget {
|
|
|
|
(DropValue value) async {
|
|
|
|
(DropValue value) async {
|
|
|
|
category = value;
|
|
|
|
category = value;
|
|
|
|
service = null;
|
|
|
|
service = null;
|
|
|
|
model.fetchProviderServices(
|
|
|
|
model.fetchProviderServices(widget.appointmentListModel.branchId.toString(), value.id.toString());
|
|
|
|
appointmentListModel.branchId
|
|
|
|
|
|
|
|
.toString(),
|
|
|
|
|
|
|
|
value.id.toString());
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
dropdownValue: category,
|
|
|
|
dropdownValue: category,
|
|
|
|
list: model.categoryDropList,
|
|
|
|
list: model.categoryDropList,
|
|
|
|
hint:
|
|
|
|
hint: LocaleKeys.selectServiceCategory.tr(),
|
|
|
|
LocaleKeys.selectServiceCategory.tr(),
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
: const Center(
|
|
|
|
: const Center(
|
|
|
|
child: CircularProgressIndicator(),
|
|
|
|
child: CircularProgressIndicator(),
|
|
|
|
@ -103,18 +116,13 @@ class AddNewServiceAppointmentPage extends StatelessWidget {
|
|
|
|
context,
|
|
|
|
context,
|
|
|
|
child: SelectItemsSheet(
|
|
|
|
child: SelectItemsSheet(
|
|
|
|
serviceId: service?.id ?? 0,
|
|
|
|
serviceId: service?.id ?? 0,
|
|
|
|
onSelectItems:
|
|
|
|
onSelectItems: (List<ItemData> selectedList) {
|
|
|
|
(List<ItemData> selectedList) {
|
|
|
|
|
|
|
|
this.selectedList.clear();
|
|
|
|
this.selectedList.clear();
|
|
|
|
this.selectedList = selectedList;
|
|
|
|
this.selectedList = selectedList;
|
|
|
|
pickedItems = [];
|
|
|
|
pickedItems = [];
|
|
|
|
for (var element
|
|
|
|
for (var element in selectedList) {
|
|
|
|
in selectedList) {
|
|
|
|
|
|
|
|
pickedItems!.add(
|
|
|
|
pickedItems!.add(
|
|
|
|
PickerItem(
|
|
|
|
PickerItem(id: element.id ?? 0, title: element.name ?? ""),
|
|
|
|
id: element.id ?? 0,
|
|
|
|
|
|
|
|
title:
|
|
|
|
|
|
|
|
element.name ?? ""),
|
|
|
|
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
model.notifyListeners();
|
|
|
|
model.notifyListeners();
|
|
|
|
@ -128,14 +136,11 @@ class AddNewServiceAppointmentPage extends StatelessWidget {
|
|
|
|
)
|
|
|
|
)
|
|
|
|
: category == null
|
|
|
|
: category == null
|
|
|
|
? Container()
|
|
|
|
? Container()
|
|
|
|
: model.services != null &&
|
|
|
|
: model.services != null && model.servicesDropList.isEmpty
|
|
|
|
model.servicesDropList.isEmpty
|
|
|
|
|
|
|
|
? const Text("No Service Found")
|
|
|
|
? const Text("No Service Found")
|
|
|
|
: const CircularProgressIndicator(),
|
|
|
|
: const CircularProgressIndicator(),
|
|
|
|
12.height,
|
|
|
|
12.height,
|
|
|
|
(service != null &&
|
|
|
|
(service != null && pickedItems != null && pickedItems!.length > 0)
|
|
|
|
pickedItems != null &&
|
|
|
|
|
|
|
|
pickedItems!.length > 0)
|
|
|
|
|
|
|
|
? ChipsPickerItem(
|
|
|
|
? ChipsPickerItem(
|
|
|
|
hint: 'Select Items',
|
|
|
|
hint: 'Select Items',
|
|
|
|
itemsList: [...pickedItems ?? []],
|
|
|
|
itemsList: [...pickedItems ?? []],
|
|
|
|
@ -145,16 +150,11 @@ class AddNewServiceAppointmentPage extends StatelessWidget {
|
|
|
|
child: SelectItemsSheet(
|
|
|
|
child: SelectItemsSheet(
|
|
|
|
serviceId: service?.id ?? 0,
|
|
|
|
serviceId: service?.id ?? 0,
|
|
|
|
list: pickedItems,
|
|
|
|
list: pickedItems,
|
|
|
|
onSelectItems:
|
|
|
|
onSelectItems: (List<ItemData> selectedList) {
|
|
|
|
(List<ItemData> selectedList) {
|
|
|
|
|
|
|
|
pickedItems = [];
|
|
|
|
pickedItems = [];
|
|
|
|
for (var element
|
|
|
|
for (var element in selectedList) {
|
|
|
|
in selectedList) {
|
|
|
|
|
|
|
|
pickedItems!.add(
|
|
|
|
pickedItems!.add(
|
|
|
|
PickerItem(
|
|
|
|
PickerItem(id: element.id ?? 0, title: element.name ?? ""),
|
|
|
|
id: element.id ?? 0,
|
|
|
|
|
|
|
|
title:
|
|
|
|
|
|
|
|
element.name ?? ""),
|
|
|
|
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
model.notifyListeners();
|
|
|
|
model.notifyListeners();
|
|
|
|
@ -166,9 +166,7 @@ class AddNewServiceAppointmentPage extends StatelessWidget {
|
|
|
|
: service != null
|
|
|
|
: service != null
|
|
|
|
? const Text("No Item Selected Yet")
|
|
|
|
? const Text("No Item Selected Yet")
|
|
|
|
: const SizedBox(),
|
|
|
|
: const SizedBox(),
|
|
|
|
if ((service != null &&
|
|
|
|
if ((service != null && pickedItems != null && pickedItems!.length > 0))
|
|
|
|
pickedItems != null &&
|
|
|
|
|
|
|
|
pickedItems!.length > 0))
|
|
|
|
|
|
|
|
Column(
|
|
|
|
Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
children: [
|
|
|
|
@ -179,8 +177,7 @@ class AddNewServiceAppointmentPage extends StatelessWidget {
|
|
|
|
color: MyColors.lightTextColor,
|
|
|
|
color: MyColors.lightTextColor,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
Row(
|
|
|
|
crossAxisAlignment:
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
|
|
CrossAxisAlignment.end,
|
|
|
|
|
|
|
|
children: [
|
|
|
|
children: [
|
|
|
|
calculatePrice().toString().toText(
|
|
|
|
calculatePrice().toString().toText(
|
|
|
|
fontSize: 29,
|
|
|
|
fontSize: 29,
|
|
|
|
@ -218,27 +215,18 @@ class AddNewServiceAppointmentPage extends StatelessWidget {
|
|
|
|
title: "Add",
|
|
|
|
title: "Add",
|
|
|
|
maxWidth: double.infinity,
|
|
|
|
maxWidth: double.infinity,
|
|
|
|
onPressed: () async {
|
|
|
|
onPressed: () async {
|
|
|
|
if (pickedItems != null &&
|
|
|
|
if (pickedItems != null && pickedItems!.length > 0) {
|
|
|
|
pickedItems!.length > 0) {
|
|
|
|
|
|
|
|
List<int> items = [];
|
|
|
|
List<int> items = [];
|
|
|
|
pickedItems?.forEach((element) {
|
|
|
|
pickedItems?.forEach((element) {
|
|
|
|
items.add(element.id);
|
|
|
|
items.add(element.id);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
Utils.showLoading(context);
|
|
|
|
Utils.showLoading(context);
|
|
|
|
var postParams = {
|
|
|
|
var postParams = {"providerBranchID": widget.appointmentListModel.branchId, "appointmentID": widget.appointmentListModel.id, "serviceItemID": items};
|
|
|
|
"providerBranchID":
|
|
|
|
MResponse res = await serviceVM!.addNewServiceInAppointment(postParams);
|
|
|
|
appointmentListModel.branchId,
|
|
|
|
_updateAppointment(context, widget.appointmentListModel.branchId ?? 0);
|
|
|
|
"appointmentID": appointmentListModel.id,
|
|
|
|
|
|
|
|
"serviceItemID": items
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
MResponse res = await serviceVM
|
|
|
|
|
|
|
|
.addNewServiceInAppointment(postParams);
|
|
|
|
|
|
|
|
_updateAppointment(context,
|
|
|
|
|
|
|
|
appointmentListModel.branchId ?? 0);
|
|
|
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
if (res.messageStatus == 1) {
|
|
|
|
if (res.messageStatus == 1) {
|
|
|
|
Utils.showToast(
|
|
|
|
Utils.showToast("Items are added Successfully");
|
|
|
|
"Items are added Successfully");
|
|
|
|
|
|
|
|
pop(context);
|
|
|
|
pop(context);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
Utils.showToast(res.message.toString());
|
|
|
|
Utils.showToast(res.message.toString());
|
|
|
|
@ -264,14 +252,7 @@ class AddNewServiceAppointmentPage extends StatelessWidget {
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> _updateAppointment(BuildContext context, int branchId) async {
|
|
|
|
Future<void> _updateAppointment(BuildContext context, int branchId) async {
|
|
|
|
await context.read<AppointmentsVM>().getMyAppointmentsForProvider({
|
|
|
|
await context.read<AppointmentsVM>().getMyAppointmentsForProvider({
|
|
|
|
"ServiceProviderID": injector
|
|
|
|
"ServiceProviderID": injector.get<AppState>().getUser.data?.userInfo?.providerId.toString() ?? "0",
|
|
|
|
.get<AppState>()
|
|
|
|
|
|
|
|
.getUser
|
|
|
|
|
|
|
|
.data
|
|
|
|
|
|
|
|
?.userInfo
|
|
|
|
|
|
|
|
?.providerId
|
|
|
|
|
|
|
|
.toString() ??
|
|
|
|
|
|
|
|
"0",
|
|
|
|
|
|
|
|
"ProviderBranchID": branchId.toString(),
|
|
|
|
"ProviderBranchID": branchId.toString(),
|
|
|
|
}, isNeedToRebuild: true);
|
|
|
|
}, isNeedToRebuild: true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|