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.
292 lines
13 KiB
Dart
292 lines
13 KiB
Dart
import 'dart:async';
|
|
import 'dart:developer';
|
|
import 'package:mc_common_app/generated/locale_keys.g.dart';
|
|
import 'package:mc_common_app/models/general_models/generic_resp_model.dart';
|
|
import 'package:mc_common_app/utils/navigator.dart';
|
|
import 'package:mc_common_app/view_models/service_view_model.dart';
|
|
import 'package:car_provider_app/views/settings/services/services_list_page.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:mc_common_app/extensions/int_extensions.dart';
|
|
import 'package:mc_common_app/extensions/string_extensions.dart';
|
|
import 'package:mc_common_app/theme/colors.dart';
|
|
import 'package:mc_common_app/utils/enums.dart';
|
|
import 'package:mc_common_app/utils/utils.dart';
|
|
import 'package:mc_common_app/widgets/button/show_fill_button.dart';
|
|
import 'package:mc_common_app/widgets/checkbox_with_title_desc.dart';
|
|
import 'package:mc_common_app/widgets/common_widgets/app_bar.dart';
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
import 'package:mc_common_app/widgets/dropdown/dropdow_field.dart';
|
|
import 'package:mc_common_app/widgets/txt_field.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
// [log] 1035 -> branch ID
|
|
// [log] HMG Branch QA II -> branchName
|
|
// [log] 8 -> category ID
|
|
// [log] Sell Car -> categegory name
|
|
// [log] New Car -> service name
|
|
|
|
class CreateServicesPage3 extends StatefulWidget {
|
|
final CreateBranchModel? branchModel;
|
|
|
|
const CreateServicesPage3(this.branchModel, {Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<CreateServicesPage3> createState() => _CreateServicesPage3State();
|
|
}
|
|
|
|
class _CreateServicesPage3State extends State<CreateServicesPage3> {
|
|
bool isAppointmentAvailable = false;
|
|
bool isHomeAppointmentAvailable = false;
|
|
int serviceRage = 0;
|
|
String chargersPerKm = "";
|
|
int? categoryId;
|
|
int? serviceId = -1;
|
|
DropValue? category;
|
|
DropValue? service;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
scheduleMicrotask(() async {
|
|
ServiceVM serviceVM = context.read<ServiceVM>();
|
|
if (widget.branchModel!.categoryId != null) {
|
|
await serviceVM.fetchServicesByCategoryId(int.parse(widget.branchModel!.categoryId ?? "0"));
|
|
|
|
category = DropValue(int.parse(widget.branchModel!.categoryId ?? "0"), widget.branchModel!.categoryName ?? "", "");
|
|
|
|
service = serviceVM.servicesDropList.firstWhere((element) => element.id == widget.branchModel!.serviceProviderService!.serviceId);
|
|
|
|
isAppointmentAvailable = widget.branchModel?.serviceProviderService?.isAllowAppointment ?? false;
|
|
serviceRage = widget.branchModel?.serviceProviderService?.customerLocationRange ?? 0;
|
|
if (serviceRage > 0) {
|
|
isHomeAppointmentAvailable = true;
|
|
}
|
|
chargersPerKm = widget.branchModel?.serviceProviderService?.rangePricePerKm ?? "";
|
|
serviceId = widget.branchModel?.serviceProviderService?.serviceProviderServiceId ?? -1;
|
|
setState(() {});
|
|
}
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: CustomAppBar(title: LocaleKeys.editServices.tr()),
|
|
body: SizedBox(
|
|
width: double.infinity,
|
|
height: double.infinity,
|
|
child: Consumer<ServiceVM>(
|
|
builder: (context, model, _) {
|
|
return Column(
|
|
children: [
|
|
Expanded(
|
|
child: SingleChildScrollView(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(20.0),
|
|
child: Column(
|
|
children: [
|
|
(widget.branchModel!.categoryId != null)
|
|
? DropdownField(
|
|
isSelectAble: false,
|
|
(DropValue value) async {
|
|
// categoryId = value.id;
|
|
// category = value;
|
|
// service = null;
|
|
// serviceId = -1;
|
|
// isAppointmentAvailable = false;
|
|
// isHomeAppointmentAvailable = false;
|
|
// model.fetchServicesByCategoryId(value.id);
|
|
},
|
|
dropdownValue: category,
|
|
list: model.categoryDropList,
|
|
hint: category != null ? category!.value : LocaleKeys.selectServiceCategory.tr(),
|
|
)
|
|
: const CircularProgressIndicator(),
|
|
12.height,
|
|
model.servicesDropList.isNotEmpty
|
|
? DropdownField(
|
|
(DropValue value) {
|
|
service = value;
|
|
isAppointmentAvailable = false;
|
|
isHomeAppointmentAvailable = false;
|
|
model.setState(ViewState.idle);
|
|
},
|
|
dropdownValue: service,
|
|
list: model.servicesDropList,
|
|
hint: LocaleKeys.defineServices.tr(),
|
|
)
|
|
: Container(),
|
|
12.height,
|
|
if (serviceId != -1) ...[
|
|
Column(
|
|
children: [
|
|
20.height,
|
|
CheckBoxWithTitleDescription(
|
|
isSelected: isAppointmentAvailable,
|
|
title: LocaleKeys.availableforAppointment.tr(),
|
|
description: LocaleKeys.bookAppointmentForServices.tr(),
|
|
onSelection: (bool v) {
|
|
isAppointmentAvailable = v;
|
|
model.setState(ViewState.idle);
|
|
},
|
|
),
|
|
20.height,
|
|
CheckBoxWithTitleDescription(
|
|
isSelected: isHomeAppointmentAvailable,
|
|
title: LocaleKeys.allowingHomeService.tr(),
|
|
description: LocaleKeys.bookAppointmentAtLocation.tr(),
|
|
onSelection: (bool v) {
|
|
isHomeAppointmentAvailable = v;
|
|
model.setState(ViewState.idle);
|
|
},
|
|
),
|
|
20.height,
|
|
if (isHomeAppointmentAvailable)
|
|
Column(
|
|
children: [
|
|
TxtField(
|
|
hint: LocaleKeys.homeServiceRange.tr(),
|
|
keyboardType: TextInputType.number,
|
|
value: serviceRage == 0 ? null : serviceRage.toString(),
|
|
postfixWidget: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
"KM".toText(color: MyColors.lightTextColor),
|
|
],
|
|
),
|
|
onChanged: (v) {
|
|
if (v.isNotEmpty) {
|
|
serviceRage = int.parse(v);
|
|
} else {
|
|
serviceRage = 0;
|
|
}
|
|
},
|
|
),
|
|
12.height,
|
|
TxtField(
|
|
hint: LocaleKeys.chargesPerKM.tr(),
|
|
keyboardType: TextInputType.number,
|
|
value: chargersPerKm == "" ? null : chargersPerKm,
|
|
onChanged: (v) {
|
|
if (v.isNotEmpty) {
|
|
chargersPerKm = v;
|
|
} else {
|
|
chargersPerKm = "";
|
|
}
|
|
},
|
|
postfixWidget: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
LocaleKeys.sar.tr().toText(color: MyColors.lightTextColor),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
]
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
if (serviceId != -1)
|
|
ShowFillButton(
|
|
title: LocaleKeys.save.tr(),
|
|
maxWidth: double.infinity,
|
|
margin: const EdgeInsets.all(20),
|
|
onPressed: () {
|
|
if (widget.branchModel!.serviceProviderService != null) {
|
|
updateService(context, model);
|
|
} else {
|
|
if (model.services != null) {
|
|
createService(context, model);
|
|
}
|
|
}
|
|
},
|
|
),
|
|
],
|
|
);
|
|
},
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
createService(BuildContext context, ServiceVM model) async {
|
|
List<Map<String, dynamic>> map = [];
|
|
model.services!.data?.forEach((element) {
|
|
if (serviceId == element.id) {
|
|
element.isSelected = true;
|
|
} else {
|
|
element.isSelected = false;
|
|
}
|
|
});
|
|
|
|
for (int i = 0; i < model.services!.data!.length; i++) {
|
|
if (model.services!.data![i].isSelected ?? false) {
|
|
var postParams = {
|
|
// "id": services!.data![i].id,
|
|
"providerBranchID": widget.branchModel!.branchId,
|
|
"serviceID": model.services!.data![i].id,
|
|
"isAllowAppointment": isAppointmentAvailable,
|
|
"isActive": true,
|
|
"customerLocationRange": serviceRage,
|
|
"rangePricePerKm": chargersPerKm.isEmpty ? "0.0" : chargersPerKm,
|
|
};
|
|
map.add(postParams);
|
|
}
|
|
}
|
|
// print(map);
|
|
Utils.showLoading(context);
|
|
GenericRespModel mResponse = await model.createService(map);
|
|
await model.getBranchAndServices();
|
|
Utils.hideLoading(context);
|
|
Utils.showToast(mResponse.message ?? "");
|
|
if (mResponse.messageStatus == 1) {
|
|
context.read<ServiceVM>().filterUserBranchCategories();
|
|
pop(context);
|
|
}
|
|
}
|
|
|
|
updateService(BuildContext context, ServiceVM model) async {
|
|
List<Map<String, dynamic>> map = [];
|
|
if (isHomeAppointmentAvailable) {
|
|
map = [
|
|
{
|
|
"id": widget.branchModel!.serviceProviderService!.serviceProviderServiceId.toString(),
|
|
"isAllowAppointment": isAppointmentAvailable,
|
|
"isActive": true,
|
|
"customerLocationRange": serviceRage,
|
|
"rangePricePerKm": chargersPerKm.isEmpty ? "0.0" : chargersPerKm,
|
|
}
|
|
];
|
|
} else {
|
|
map = [
|
|
{
|
|
"id": widget.branchModel!.serviceProviderService!.serviceProviderServiceId.toString(),
|
|
"isAllowAppointment": isAppointmentAvailable,
|
|
"isActive": true,
|
|
}
|
|
];
|
|
}
|
|
|
|
// print(map);
|
|
Utils.showLoading(context);
|
|
GenericRespModel mResponse = await model.updateServices(map);
|
|
model.getBranchAndServices();
|
|
model.filterUserBranchCategories();
|
|
Utils.hideLoading(context);
|
|
Utils.showToast(mResponse.message ?? "");
|
|
if (mResponse.messageStatus == 1) {
|
|
context.read<ServiceVM>().filterUserBranchCategories();
|
|
pop(context);
|
|
}
|
|
}
|
|
}
|