This commit is contained in:
Hamza-Ayed
2024-09-21 00:19:38 +03:00
parent 519f4b651c
commit 3313cb0203
8 changed files with 780 additions and 517 deletions

View File

@@ -0,0 +1,66 @@
import 'dart:convert';
import 'package:SEFER/constant/box_name.dart';
import 'package:SEFER/constant/links.dart';
import 'package:SEFER/controller/functions/crud.dart';
import 'package:SEFER/main.dart';
import 'package:get/get.dart';
import '../../../../constant/colors.dart';
class AssuranceHealthController extends GetxController {
bool isLoading = false;
Map tripCount = {};
Future getTripCountByCaptain() async {
var res = await CRUD().get(link: AppLink.getTripCountByCaptain, payload: {
"driver_id": box.read(BoxName.driverID).toString(),
});
if (res != 'failure') {
tripCount = jsonDecode(res)['message'];
update();
}
}
Future<void> addDriverHealthAssurance({
String? driverId,
String? assured,
required String healthInsuranceProvider,
}) async {
// Define the URL to your PHP backend
// Data to be sent to the backend
Map<String, String> data = {
"driver_id": box.read(BoxName.driverID).toString(),
"assured": '1',
"health_insurance_provider": healthInsuranceProvider,
};
try {
// Send the POST request to your backend
var response = await CRUD()
.post(link: AppLink.addHealthInsuranceProvider, payload: data);
if (response != 'failure') {
// Handle success (e.g., show a success message)
print("Health assurance data saved successfully");
Get.snackbar(
"Success".tr,
"You have successfully opted for health insurance.".tr,
backgroundColor: AppColor.greenColor,
);
} else {
// Handle failure (e.g., show an error message)
print("Failed to save health assurance data");
Get.snackbar(
"Error".tr,
"Please enter a health insurance status.".tr,
backgroundColor: AppColor.redColor,
);
}
} catch (e) {
// Handle any errors
print("Error: $e");
}
}
}