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/constant/style.dart';
|
||||||
import 'package:SEFER/controller/functions/crud.dart';
|
import 'package:SEFER/controller/functions/crud.dart';
|
||||||
import 'package:SEFER/main.dart';
|
import 'package:SEFER/main.dart';
|
||||||
|
import 'package:SEFER/views/home/Captin/home_captain/home_captin.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:image_cropper/image_cropper.dart';
|
import 'package:image_cropper/image_cropper.dart';
|
||||||
@@ -20,7 +21,8 @@ import 'upload_image.dart';
|
|||||||
|
|
||||||
class AI extends GetxController {
|
class AI extends GetxController {
|
||||||
bool approved = false;
|
bool approved = false;
|
||||||
|
bool isDriverSaved = false;
|
||||||
|
bool isCarSaved = false;
|
||||||
void setApproved() {
|
void setApproved() {
|
||||||
approved = true;
|
approved = true;
|
||||||
update();
|
update();
|
||||||
@@ -191,57 +193,106 @@ class AI extends GetxController {
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
isLoading = true;
|
|
||||||
update();
|
|
||||||
await addDriverEgypt();
|
await addDriverEgypt();
|
||||||
await addRegistrationCarEgypt();
|
await addRegistrationCarEgypt();
|
||||||
isLoading = false;
|
|
||||||
update();
|
if (isCarSaved && isDriverSaved) {
|
||||||
|
Get.to(() => HomeCaptain());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> addDriverEgypt() async {
|
Future<void> addDriverEgypt() async {
|
||||||
try {
|
try {
|
||||||
var res = await CRUD().post(link: AppLink.signUpCaptin, payload: {
|
print(box.read(BoxName.driverID).toString());
|
||||||
'first_name': responseIdEgyptDriverLicense['firstName'],
|
|
||||||
'last_name': responseIdEgyptDriverLicense['lastName'],
|
// Extract values from box or set defaults
|
||||||
'email': box.read(BoxName.emailDriver),
|
var firstName = responseIdEgyptDriverLicense['firstName'] ?? '';
|
||||||
'phone': '78787', //todo add phone //box.read(BoxName.phoneDriver),
|
var lastName = responseIdEgyptDriverLicense['lastName'] ?? '';
|
||||||
'driverId': box.read(BoxName.driverID),
|
var email = box.read(BoxName.emailDriver) ?? '';
|
||||||
'password': '123456', // todo check
|
var phone = box.read(BoxName.phoneDriver)?.toString() ?? '';
|
||||||
'gender': responseIdEgyptBack['gender'] == 'ذكر' ? 'Male' : 'Female',
|
var driverId = box.read(BoxName.driverID)?.toString() ?? '';
|
||||||
'license_type': responseIdEgyptDriverLicense['license_type'],
|
var password = '123456';
|
||||||
'national_number': responseIdEgyptBack['nationalID'],
|
var gender = responseIdEgyptBack['gender'] == 'ذكر' ? 'Male' : 'Female';
|
||||||
'name_arabic': responseIdEgyptDriverLicense['name_arabic'],
|
var licenseType = responseIdEgyptDriverLicense['license_type'] ?? '';
|
||||||
'name_english': responseIdEgyptDriverLicense['name_english'],
|
var nationalNumber = responseIdEgyptBack['nationalID'] ?? '';
|
||||||
'issue_date': responseIdEgyptDriverLicense['issue_date'],
|
var nameArabic = responseIdEgyptDriverLicense['name_arabic'] ?? '';
|
||||||
'expiry_date': responseIdEgyptDriverLicense['expiry_date'],
|
var nameEnglish = responseIdEgyptDriverLicense['name_english'] ?? '';
|
||||||
'license_categories':
|
var issueDate = responseIdEgyptDriverLicense['issue_date'] ?? '';
|
||||||
responseIdEgyptDriverLicense['license_categories'],
|
var expiryDate = responseIdEgyptDriverLicense['expiry_date'] ?? '';
|
||||||
'address': responseIdEgyptFront['address'],
|
var licenseCategories =
|
||||||
'card_id': responseIdEgyptFront['card_id'],
|
responseIdEgyptDriverLicense['license_categories'] ?? '';
|
||||||
'occupation': responseIdEgyptBack['occupation'],
|
var address = responseIdEgyptFront['address'] ?? '';
|
||||||
'education': responseIdEgyptBack['occupation'],
|
var cardId = responseIdEgyptFront['card_id'] ?? '';
|
||||||
'licenseIssueDate': responseIdEgyptDriverLicense['issue_date'],
|
var occupation = responseIdEgyptBack['occupation'] ?? '';
|
||||||
'religion': responseIdEgyptBack['religion'],
|
var education = responseIdEgyptBack['occupation'] ?? '';
|
||||||
'status': responseIdEgyptBack['fullName'],
|
var licenseIssueDate = responseIdEgyptDriverLicense['issue_date'] ?? '';
|
||||||
'birthdate': responseIdEgyptFront['dob'] + '-01-01',
|
var religion = responseIdEgyptBack['religion'] ?? '';
|
||||||
'maritalStatus': responseIdEgyptBack['maritalStatus'],
|
var status = responseIdEgyptBack['fullName'] ?? '';
|
||||||
'site': responseIdEgyptDriverLicense['address'],
|
var birthdate = responseIdEgyptFront['dob'] != null
|
||||||
'employmentType': responseIdEgyptDriverLicense['employmentType'],
|
? responseIdEgyptFront['dob'] + '-01-01'
|
||||||
});
|
: '';
|
||||||
var status = jsonDecode(res);
|
var maritalStatus = responseIdEgyptBack['maritalStatus'] ?? '';
|
||||||
if (status == 'success') {
|
var site = responseIdEgyptDriverLicense['address'] ?? '';
|
||||||
Get.snackbar('Success', 'message',
|
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);
|
backgroundColor: AppColor.greenColor);
|
||||||
|
} else {
|
||||||
|
Get.snackbar('Error', 'Failed to save driver data',
|
||||||
|
backgroundColor: Colors.red);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} 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 {
|
Future addRegistrationCarEgypt() async {
|
||||||
try {
|
try {
|
||||||
|
isLoading = true;
|
||||||
|
update();
|
||||||
var res = await CRUD().post(link: AppLink.addRegisrationCar, payload: {
|
var res = await CRUD().post(link: AppLink.addRegisrationCar, payload: {
|
||||||
'driverID': box.read(BoxName.driverID),
|
'driverID': box.read(BoxName.driverID),
|
||||||
'vin': responseIdCardDriverEgyptBack['chassis'].toString(),
|
'vin': responseIdCardDriverEgyptBack['chassis'].toString(),
|
||||||
@@ -260,8 +311,11 @@ class AI extends GetxController {
|
|||||||
'registration_date':
|
'registration_date':
|
||||||
'${responseIdCardDriverEgyptBack['inspection_date']}-01-01',
|
'${responseIdCardDriverEgyptBack['inspection_date']}-01-01',
|
||||||
});
|
});
|
||||||
|
isLoading = false;
|
||||||
|
update();
|
||||||
var status = jsonDecode(res);
|
var status = jsonDecode(res);
|
||||||
if (status == 'success') {
|
if (status['status'] == 'success') {
|
||||||
|
isCarSaved = true;
|
||||||
Get.snackbar('Success', 'message',
|
Get.snackbar('Success', 'message',
|
||||||
backgroundColor: AppColor.greenColor);
|
backgroundColor: AppColor.greenColor);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,15 @@ class EgyptCardAI extends StatelessWidget {
|
|||||||
|
|
||||||
return MyScafolld(
|
return MyScafolld(
|
||||||
title: 'Documents check'.tr,
|
title: 'Documents check'.tr,
|
||||||
|
action: GetBuilder<AI>(builder: (cont) {
|
||||||
|
return IconButton(
|
||||||
|
onPressed: () {
|
||||||
|
cont.isLoading = false;
|
||||||
|
cont.update();
|
||||||
|
},
|
||||||
|
icon: const Icon(Icons.refresh),
|
||||||
|
);
|
||||||
|
}),
|
||||||
body: [
|
body: [
|
||||||
GetBuilder<AI>(builder: (controller) {
|
GetBuilder<AI>(builder: (controller) {
|
||||||
return controller.isLoading
|
return controller.isLoading
|
||||||
|
|||||||
Reference in New Issue
Block a user