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.
274 lines
13 KiB
Dart
274 lines
13 KiB
Dart
|
|
import 'package:car_provider_app/generated/locale_keys.g.dart';
|
|
import 'package:car_provider_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/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/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/extensions/extensions_widget.dart';
|
|
import 'package:mc_common_app/widgets/txt_field.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
class CreateServicesPage3 extends StatelessWidget {
|
|
CreateBranchModel? branchModel;
|
|
|
|
CreateServicesPage3(this.branchModel, {Key? key}) : super(key: key);
|
|
|
|
bool isAppointmentAvailable = false;
|
|
bool isHomeAppointmentAvailable = false;
|
|
int serviceRage = 0;
|
|
String chargersPerKm = "0";
|
|
int? categoryId;
|
|
int? serviceId = -1;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
ServiceVM serviceVM = context.read<ServiceVM>();
|
|
if (branchModel!.categoryId == null) {
|
|
serviceVM.fetchBranchCategory(EasyLocalization.of(context)?.currentLocale?.countryCode ?? "SA");
|
|
} else {
|
|
isAppointmentAvailable = branchModel?.serviceProviderService?.isAllowAppointment ?? false;
|
|
// isHomeAppointmentAvailable=branchModel.serviceProviderService.
|
|
serviceRage = branchModel?.serviceProviderService?.customerLocationRange ?? 0;
|
|
if (serviceRage > 0) {
|
|
isHomeAppointmentAvailable = true;
|
|
}
|
|
chargersPerKm = branchModel?.serviceProviderService?.rangePricePerKm ?? "0";
|
|
serviceId = branchModel?.serviceProviderService?.serviceId ?? -1;
|
|
}
|
|
return Scaffold(
|
|
appBar: CustomAppBar(title: LocaleKeys.defineServices.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: [
|
|
Text(
|
|
branchModel!.branchName ?? "N/A",
|
|
style: const TextStyle(
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
).toContainer(
|
|
padding: const EdgeInsets.only(left: 8, right: 8, bottom: 12, top: 12),
|
|
backgroundColor: MyColors.textFieldColor,
|
|
borderRadius: 0,
|
|
width: double.infinity,
|
|
),
|
|
12.height,
|
|
(branchModel!.categoryId != null)
|
|
? Text(
|
|
branchModel!.categoryName ?? "N/A",
|
|
style: const TextStyle(
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
).toContainer(
|
|
padding: const EdgeInsets.only(left: 8, right: 8, bottom: 12, top: 12),
|
|
backgroundColor: MyColors.textFieldColor,
|
|
borderRadius: 0,
|
|
width: double.infinity,
|
|
)
|
|
: (branchModel!.categoryId == null && model.categoryDropList.isNotEmpty)
|
|
? DropdownField(
|
|
(DropValue value) async {
|
|
categoryId = value.id;
|
|
serviceId = -1;
|
|
isAppointmentAvailable = false;
|
|
isHomeAppointmentAvailable = false;
|
|
model.fetchServicesByCategoryId(value.id.toString());
|
|
},
|
|
list: model.categoryDropList,
|
|
hint: LocaleKeys.selectServiceCategory.tr(),
|
|
)
|
|
: const CircularProgressIndicator(),
|
|
12.height,
|
|
branchModel!.serviceProviderService != null
|
|
? Text(
|
|
branchModel!.serviceProviderService!.serviceDescription ?? "N/A",
|
|
style: const TextStyle(
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
).toContainer(
|
|
padding: const EdgeInsets.only(left: 8, right: 8, bottom: 12, top: 12),
|
|
backgroundColor: MyColors.textFieldColor,
|
|
borderRadius: 0,
|
|
width: double.infinity,
|
|
)
|
|
: model.servicesDropList.isNotEmpty
|
|
? DropdownField(
|
|
(DropValue value) {
|
|
serviceId = value.id;
|
|
isAppointmentAvailable = false;
|
|
isHomeAppointmentAvailable = false;
|
|
model.setState(ViewState.idle);
|
|
},
|
|
list: model.servicesDropList,
|
|
hint: LocaleKeys.defineServices.tr(),
|
|
)
|
|
: categoryId == null
|
|
? Container()
|
|
: const CircularProgressIndicator(),
|
|
12.height,
|
|
if (serviceId != -1)
|
|
Column(
|
|
children: [
|
|
20.height,
|
|
CheckBoxWithTitleDescription(
|
|
isSelected: isAppointmentAvailable,
|
|
title: 'Available for appointment',
|
|
description: 'This option will allow customer to book appointment for these services',
|
|
onSelection: (bool v) {
|
|
isAppointmentAvailable = v;
|
|
model.setState(ViewState.idle);
|
|
},
|
|
),
|
|
20.height,
|
|
CheckBoxWithTitleDescription(
|
|
isSelected: isHomeAppointmentAvailable,
|
|
title: 'Allow home services',
|
|
description: 'This option will allow customer to book appointment at their desired location',
|
|
onSelection: (bool v) {
|
|
isHomeAppointmentAvailable = v;
|
|
model.setState(ViewState.idle);
|
|
},
|
|
),
|
|
20.height,
|
|
if (isHomeAppointmentAvailable)
|
|
Column(
|
|
children: [
|
|
TxtField(
|
|
hint: "Home Services Range",
|
|
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: "Charges per Kilometer",
|
|
keyboardType: TextInputType.number,
|
|
value: chargersPerKm == "0.0" ? null : chargersPerKm,
|
|
onChanged: (v) {
|
|
if (v.isNotEmpty) {
|
|
chargersPerKm = v;
|
|
} else {
|
|
chargersPerKm = "0";
|
|
}
|
|
},
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
if (serviceId != -1)
|
|
ShowFillButton(
|
|
title: LocaleKeys.save.tr(),
|
|
maxWidth: double.infinity,
|
|
margin: const EdgeInsets.all(20),
|
|
onPressed: () {
|
|
if (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": branchModel!.branchId,
|
|
"serviceID": model.services!.data![i].id,
|
|
"isAllowAppointment": isAppointmentAvailable,
|
|
"isActive": true,
|
|
"customerLocationRange": serviceRage,
|
|
"rangePricePerKm": chargersPerKm
|
|
};
|
|
map.add(postParams);
|
|
}
|
|
}
|
|
// print(map);
|
|
Utils.showLoading(context);
|
|
MResponse mResponse = await model.createService(map);
|
|
model.getBranchAndServices();
|
|
Utils.hideLoading(context);
|
|
Utils.showToast(mResponse.message ?? "");
|
|
}
|
|
|
|
updateService(BuildContext context, ServiceVM model) async {
|
|
List<Map<String, dynamic>> map = [
|
|
{
|
|
"id": branchModel!.serviceProviderService!.serviceId.toString(),
|
|
"isAllowAppointment": isAppointmentAvailable,
|
|
"isActive": true,
|
|
"customerLocationRange": serviceRage,
|
|
"rangePricePerKm": chargersPerKm
|
|
}
|
|
];
|
|
|
|
// print(map);
|
|
Utils.showLoading(context);
|
|
MResponse mResponse = await model.updateServices(map);
|
|
model.getBranchAndServices();
|
|
Utils.hideLoading(context);
|
|
Utils.showToast(mResponse.message ?? "");
|
|
}
|
|
}
|