5/18/2
This commit is contained in:
@@ -5,6 +5,7 @@ import 'package:SEFER/constant/links.dart';
|
||||
import 'package:SEFER/constant/style.dart';
|
||||
import 'package:SEFER/controller/functions/crud.dart';
|
||||
import 'package:SEFER/main.dart';
|
||||
import 'package:SEFER/views/home/Captin/home_captain/home_captin.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:image_cropper/image_cropper.dart';
|
||||
@@ -20,7 +21,8 @@ import 'upload_image.dart';
|
||||
|
||||
class AI extends GetxController {
|
||||
bool approved = false;
|
||||
|
||||
bool isDriverSaved = false;
|
||||
bool isCarSaved = false;
|
||||
void setApproved() {
|
||||
approved = true;
|
||||
update();
|
||||
@@ -191,57 +193,106 @@ class AI extends GetxController {
|
||||
],
|
||||
);
|
||||
} else {
|
||||
isLoading = true;
|
||||
update();
|
||||
await addDriverEgypt();
|
||||
await addRegistrationCarEgypt();
|
||||
isLoading = false;
|
||||
update();
|
||||
|
||||
if (isCarSaved && isDriverSaved) {
|
||||
Get.to(() => HomeCaptain());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> addDriverEgypt() async {
|
||||
try {
|
||||
var res = await CRUD().post(link: AppLink.signUpCaptin, payload: {
|
||||
'first_name': responseIdEgyptDriverLicense['firstName'],
|
||||
'last_name': responseIdEgyptDriverLicense['lastName'],
|
||||
'email': box.read(BoxName.emailDriver),
|
||||
'phone': '78787', //todo add phone //box.read(BoxName.phoneDriver),
|
||||
'driverId': box.read(BoxName.driverID),
|
||||
'password': '123456', // todo check
|
||||
'gender': responseIdEgyptBack['gender'] == 'ذكر' ? 'Male' : 'Female',
|
||||
'license_type': responseIdEgyptDriverLicense['license_type'],
|
||||
'national_number': responseIdEgyptBack['nationalID'],
|
||||
'name_arabic': responseIdEgyptDriverLicense['name_arabic'],
|
||||
'name_english': responseIdEgyptDriverLicense['name_english'],
|
||||
'issue_date': responseIdEgyptDriverLicense['issue_date'],
|
||||
'expiry_date': responseIdEgyptDriverLicense['expiry_date'],
|
||||
'license_categories':
|
||||
responseIdEgyptDriverLicense['license_categories'],
|
||||
'address': responseIdEgyptFront['address'],
|
||||
'card_id': responseIdEgyptFront['card_id'],
|
||||
'occupation': responseIdEgyptBack['occupation'],
|
||||
'education': responseIdEgyptBack['occupation'],
|
||||
'licenseIssueDate': responseIdEgyptDriverLicense['issue_date'],
|
||||
'religion': responseIdEgyptBack['religion'],
|
||||
'status': responseIdEgyptBack['fullName'],
|
||||
'birthdate': responseIdEgyptFront['dob'] + '-01-01',
|
||||
'maritalStatus': responseIdEgyptBack['maritalStatus'],
|
||||
'site': responseIdEgyptDriverLicense['address'],
|
||||
'employmentType': responseIdEgyptDriverLicense['employmentType'],
|
||||
});
|
||||
var status = jsonDecode(res);
|
||||
if (status == 'success') {
|
||||
Get.snackbar('Success', 'message',
|
||||
print(box.read(BoxName.driverID).toString());
|
||||
|
||||
// Extract values from box or set defaults
|
||||
var firstName = responseIdEgyptDriverLicense['firstName'] ?? '';
|
||||
var lastName = responseIdEgyptDriverLicense['lastName'] ?? '';
|
||||
var email = box.read(BoxName.emailDriver) ?? '';
|
||||
var phone = box.read(BoxName.phoneDriver)?.toString() ?? '';
|
||||
var driverId = box.read(BoxName.driverID)?.toString() ?? '';
|
||||
var password = '123456';
|
||||
var gender = responseIdEgyptBack['gender'] == 'ذكر' ? 'Male' : 'Female';
|
||||
var licenseType = responseIdEgyptDriverLicense['license_type'] ?? '';
|
||||
var nationalNumber = responseIdEgyptBack['nationalID'] ?? '';
|
||||
var nameArabic = responseIdEgyptDriverLicense['name_arabic'] ?? '';
|
||||
var nameEnglish = responseIdEgyptDriverLicense['name_english'] ?? '';
|
||||
var issueDate = responseIdEgyptDriverLicense['issue_date'] ?? '';
|
||||
var expiryDate = responseIdEgyptDriverLicense['expiry_date'] ?? '';
|
||||
var licenseCategories =
|
||||
responseIdEgyptDriverLicense['license_categories'] ?? '';
|
||||
var address = responseIdEgyptFront['address'] ?? '';
|
||||
var cardId = responseIdEgyptFront['card_id'] ?? '';
|
||||
var occupation = responseIdEgyptBack['occupation'] ?? '';
|
||||
var education = responseIdEgyptBack['occupation'] ?? '';
|
||||
var licenseIssueDate = responseIdEgyptDriverLicense['issue_date'] ?? '';
|
||||
var religion = responseIdEgyptBack['religion'] ?? '';
|
||||
var status = responseIdEgyptBack['fullName'] ?? '';
|
||||
var birthdate = responseIdEgyptFront['dob'] != null
|
||||
? responseIdEgyptFront['dob'] + '-01-01'
|
||||
: '';
|
||||
var maritalStatus = responseIdEgyptBack['maritalStatus'] ?? '';
|
||||
var site = responseIdEgyptDriverLicense['address'] ?? '';
|
||||
var employmentType = responseIdEgyptDriverLicense['employmentType'] ?? '';
|
||||
|
||||
// Create payload
|
||||
var payload = {
|
||||
'first_name': firstName,
|
||||
'last_name': lastName,
|
||||
'email': email,
|
||||
'phone': phone,
|
||||
'driverId': driverId,
|
||||
'password': password,
|
||||
'gender': gender,
|
||||
'license_type': licenseType,
|
||||
'national_number': nationalNumber,
|
||||
'name_arabic': nameArabic,
|
||||
'name_english': nameEnglish,
|
||||
'issue_date': issueDate,
|
||||
'expiry_date': expiryDate,
|
||||
'license_categories': licenseCategories,
|
||||
'address': address,
|
||||
'card_id': cardId,
|
||||
'occupation': occupation,
|
||||
'education': education,
|
||||
'licenseIssueDate': licenseIssueDate,
|
||||
'religion': religion,
|
||||
'status': status,
|
||||
'birthdate': birthdate,
|
||||
'maritalStatus': maritalStatus,
|
||||
'site': site,
|
||||
'employmentType': employmentType,
|
||||
};
|
||||
isLoading = true;
|
||||
update();
|
||||
// Make POST request
|
||||
var res = await CRUD().post(link: AppLink.signUpCaptin, payload: payload);
|
||||
var status1 = jsonDecode(res);
|
||||
isLoading = false;
|
||||
update();
|
||||
// Handle response
|
||||
|
||||
print(status1);
|
||||
if (status1['status'] == 'success') {
|
||||
isDriverSaved = true;
|
||||
Get.snackbar('Success', 'Driver data saved successfully',
|
||||
backgroundColor: AppColor.greenColor);
|
||||
} else {
|
||||
Get.snackbar('Error', 'Failed to save driver data',
|
||||
backgroundColor: Colors.red);
|
||||
}
|
||||
} catch (e) {
|
||||
print('error is $e');
|
||||
print('Error: $e');
|
||||
Get.snackbar('Error', 'An error occurred while saving driver data',
|
||||
backgroundColor: Colors.red);
|
||||
}
|
||||
}
|
||||
|
||||
Future addRegistrationCarEgypt() async {
|
||||
try {
|
||||
isLoading = true;
|
||||
update();
|
||||
var res = await CRUD().post(link: AppLink.addRegisrationCar, payload: {
|
||||
'driverID': box.read(BoxName.driverID),
|
||||
'vin': responseIdCardDriverEgyptBack['chassis'].toString(),
|
||||
@@ -260,8 +311,11 @@ class AI extends GetxController {
|
||||
'registration_date':
|
||||
'${responseIdCardDriverEgyptBack['inspection_date']}-01-01',
|
||||
});
|
||||
isLoading = false;
|
||||
update();
|
||||
var status = jsonDecode(res);
|
||||
if (status == 'success') {
|
||||
if (status['status'] == 'success') {
|
||||
isCarSaved = true;
|
||||
Get.snackbar('Success', 'message',
|
||||
backgroundColor: AppColor.greenColor);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user