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.
186 lines
6.5 KiB
Dart
186 lines
6.5 KiB
Dart
import 'package:car_provider_app/api/client/branch_api_client.dart';
|
|
import 'package:car_provider_app/classes/utils.dart';
|
|
import 'package:car_provider_app/models/m_response.dart';
|
|
import 'package:car_provider_app/models/profile/branch.dart';
|
|
import 'package:car_provider_app/models/profile/categroy.dart';
|
|
import 'package:car_provider_app/models/profile/services.dart';
|
|
import 'package:car_provider_app/models/user/country.dart';
|
|
import 'package:car_provider_app/widgets/dropdown/dropdow_field.dart';
|
|
import 'package:car_provider_app/widgets/show_fill_button.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:car_provider_app/extensions/int_extensions.dart';
|
|
import 'package:car_provider_app/extensions/string_extensions.dart';
|
|
|
|
class CreateServicesPage extends StatefulWidget {
|
|
@override
|
|
State<CreateServicesPage> createState() => _CreateServicesPageState();
|
|
}
|
|
|
|
class _CreateServicesPageState extends State<CreateServicesPage> {
|
|
String? branchName;
|
|
int categoryId = -1, branchId = -1;
|
|
|
|
List<DropValue> countryDropList = [];
|
|
List<DropValue> categoryDropList = [];
|
|
|
|
Branch? branch;
|
|
Category? category;
|
|
Services? services;
|
|
|
|
@override
|
|
void initState() {
|
|
// TODO: implement initState
|
|
super.initState();
|
|
fetchBranches();
|
|
}
|
|
|
|
fetchBranches() async {
|
|
branch = await BranchApiClent().fetchAllBranches();
|
|
setState(() {
|
|
branch!.data?.forEach((element) {
|
|
countryDropList.add(new DropValue(element.id ?? 0, ((element.branchName!.isEmpty ? "N/A" : element.branchName) ?? "N/A"), ""));
|
|
});
|
|
});
|
|
}
|
|
|
|
fetchBrancheCategory() async {
|
|
category = await BranchApiClent().fetchBranchCategory();
|
|
setState(() {
|
|
category!.data?.forEach((element) {
|
|
categoryDropList.add(new DropValue(element.id ?? 0, ((element.categoryName!.isEmpty ? "N/A" : element.categoryName) ?? "N/A"), ""));
|
|
});
|
|
});
|
|
}
|
|
|
|
fetchServices() async {
|
|
services = await BranchApiClent().fetchServices(categoryId.toString());
|
|
setState(() {});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text("Define Services"),
|
|
),
|
|
body: Container(
|
|
width: double.infinity,
|
|
height: double.infinity,
|
|
child: Column(
|
|
children: [
|
|
Expanded(
|
|
child: SingleChildScrollView(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(12.0),
|
|
child: Column(
|
|
children: [
|
|
branch != null
|
|
? DropdownField((DropValue value) {
|
|
setState(() {
|
|
// countryCode = value.subValue;
|
|
// countryId = value.id;
|
|
// fetchCites();
|
|
branchId = value.id;
|
|
fetchBrancheCategory();
|
|
});
|
|
}, list: countryDropList, hint: "Select Branch")
|
|
: CircularProgressIndicator(),
|
|
12.height,
|
|
(category != null)
|
|
? DropdownField((DropValue value) {
|
|
setState(() {
|
|
// countryCode = value.subValue;
|
|
// countryId = value.id;
|
|
// fetchCites();
|
|
categoryId = value.id;
|
|
fetchServices();
|
|
});
|
|
}, list: categoryDropList, hint: "Select Service Category")
|
|
: branchId == -1
|
|
? Container()
|
|
: CircularProgressIndicator(),
|
|
12.height,
|
|
if (services != null)
|
|
ListView.separated(
|
|
itemBuilder: (context, index) {
|
|
return Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: Row(
|
|
children: [
|
|
Checkbox(
|
|
value: services!.data![index].isSelected,
|
|
onChanged: (v) {
|
|
setState(() {
|
|
services!.data![index].isSelected = v;
|
|
});
|
|
},
|
|
),
|
|
12.width,
|
|
(services!.data![index].description ?? "").toText12()
|
|
],
|
|
),
|
|
);
|
|
},
|
|
separatorBuilder: (context, index) {
|
|
return 1.height;
|
|
},
|
|
itemCount: services!.data!.length,
|
|
physics: NeverScrollableScrollPhysics(),
|
|
shrinkWrap: true,
|
|
)
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
if (checkServicesSelection())
|
|
Padding(
|
|
padding: const EdgeInsets.all(12.0),
|
|
child: ShowFillButton(
|
|
title: "Save",
|
|
width: double.infinity,
|
|
onPressed: () {
|
|
createService();
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
bool checkServicesSelection() {
|
|
bool isServiceSelected = false;
|
|
try {
|
|
services!.data!.forEach((element) {
|
|
if (element.isSelected ?? false) isServiceSelected = true;
|
|
});
|
|
} catch (e) {
|
|
isServiceSelected = false;
|
|
}
|
|
|
|
return isServiceSelected;
|
|
}
|
|
|
|
createService() async {
|
|
List<Map<String, dynamic>> map = [];
|
|
for (int i = 0; i < services!.data!.length; i++) {
|
|
if (services!.data![i].isSelected ?? false) {
|
|
var postParams = {
|
|
// "id": services!.data![i].id,
|
|
"providerBranchID": branchId,
|
|
"serviceID": services!.data![i].id,
|
|
"isAllowAppointment": true,
|
|
"isActive": true
|
|
};
|
|
map.add(postParams);
|
|
}
|
|
}
|
|
Utils.showLoading(context);
|
|
MResponse mResponse = await BranchApiClent().createService(map);
|
|
Utils.hideLoading(context);
|
|
Utils.showToast(mResponse.message ?? "");
|
|
}
|
|
}
|