25-5-9/1
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:math';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
@@ -12,13 +13,17 @@ import '../../constant/links.dart';
|
||||
import '../../constant/style.dart';
|
||||
import '../../main.dart';
|
||||
import '../../print.dart';
|
||||
import '../../views/widgets/mycircular.dart';
|
||||
import '../functions/crud.dart';
|
||||
import '../functions/image.dart';
|
||||
import '../functions/launch.dart';
|
||||
|
||||
enum DocumentType {
|
||||
carLicenseFront,
|
||||
carLicenseBack,
|
||||
idCardFront,
|
||||
nonIdCardFront,
|
||||
nonIdCardBack,
|
||||
idCardBack,
|
||||
driverLicense,
|
||||
unknown,
|
||||
@@ -31,6 +36,7 @@ class RegisterCaptainController extends GetxController {
|
||||
String? driverId;
|
||||
String? email;
|
||||
String? phone;
|
||||
bool isEgypt = true;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
@@ -47,6 +53,12 @@ class RegisterCaptainController extends GetxController {
|
||||
initArguments();
|
||||
}
|
||||
|
||||
changeNationality() {
|
||||
isEgypt = !isEgypt;
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
void initArguments() {
|
||||
if (arguments != null) {
|
||||
driverId = arguments!['driverId'];
|
||||
@@ -67,6 +79,8 @@ class RegisterCaptainController extends GetxController {
|
||||
Map<String, dynamic> responseIdEgyptFront = {};
|
||||
Map<String, dynamic> responseCriminalRecordEgypt = {};
|
||||
Map<String, dynamic> responseIdEgyptBack = {};
|
||||
Map<String, dynamic> responseNonIdCardFront = {};
|
||||
Map<String, dynamic> responseNonIdCardBack = {};
|
||||
Map<String, dynamic> responseIdEgyptDriverLicense = {};
|
||||
String? responseIdCardDriverEgypt1;
|
||||
bool isloading = false;
|
||||
@@ -180,21 +194,21 @@ class RegisterCaptainController extends GetxController {
|
||||
String expectedDocument = getExpectedDocument(imagePath);
|
||||
String detectedDocument = getDetectedDocument(detectedType);
|
||||
|
||||
bool isCorrectDocument = (detectedType == getExpectedType(imagePath));
|
||||
if (!isCorrectDocument) {
|
||||
Get.defaultDialog(
|
||||
title: 'incorrect_document_title'.tr,
|
||||
middleText:
|
||||
'${'expected'.tr}: $expectedDocument\n${'detected'.tr}: $detectedDocument',
|
||||
confirm: MyElevatedButton(
|
||||
title: 'OK'.tr,
|
||||
onPressed: () {
|
||||
Get.back();
|
||||
}));
|
||||
} else {
|
||||
// Process the correct document
|
||||
await anthropicAI(textValues, prompt, imagePath);
|
||||
}
|
||||
// bool isCorrectDocument = (detectedType == getExpectedType(imagePath));
|
||||
// if (!isCorrectDocument) {
|
||||
// Get.defaultDialog(
|
||||
// title: 'incorrect_document_title'.tr,
|
||||
// middleText:
|
||||
// '${'expected'.tr}: $expectedDocument\n${'detected'.tr}: $detectedDocument',
|
||||
// confirm: MyElevatedButton(
|
||||
// title: 'OK'.tr,
|
||||
// onPressed: () {
|
||||
// Get.back();
|
||||
// }));
|
||||
// } else {
|
||||
// Process the correct document
|
||||
await anthropicAI(textValues, prompt, imagePath);
|
||||
// }
|
||||
isLoading = false;
|
||||
update();
|
||||
}
|
||||
@@ -417,6 +431,8 @@ class RegisterCaptainController extends GetxController {
|
||||
|
||||
String extractDOB(String nationalNumber) {
|
||||
if (nationalNumber.length != 14) {
|
||||
Get.snackbar('National number must be 14 digits long.', 'message',
|
||||
backgroundColor: AppColor.redColor);
|
||||
throw ArgumentError('National number must be 14 digits long.');
|
||||
}
|
||||
|
||||
@@ -448,11 +464,120 @@ class RegisterCaptainController extends GetxController {
|
||||
return dob;
|
||||
}
|
||||
|
||||
String generatePassword({int length = 8}) {
|
||||
const String upperCaseLetters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
const String lowerCaseLetters = 'abcdefghijklmnopqrstuvwxyz';
|
||||
const String digits = '0123456789';
|
||||
const String specialCharacters = '!@#\$%^&*()-_=+[]{}|;:,.<>?';
|
||||
|
||||
const String allChars =
|
||||
upperCaseLetters + lowerCaseLetters + digits + specialCharacters;
|
||||
final Random random = Random();
|
||||
|
||||
// Generate a random password of the specified length
|
||||
String password = List.generate(length, (index) {
|
||||
int randomIndex = random.nextInt(allChars.length);
|
||||
return allChars[randomIndex];
|
||||
}).join();
|
||||
|
||||
return password;
|
||||
}
|
||||
|
||||
Future<void> addDriverForeign() async {
|
||||
isLoading = true;
|
||||
update();
|
||||
var added = await storage.read(key: 'name');
|
||||
String newPassword = generatePassword();
|
||||
print('Generated Password: $newPassword');
|
||||
var payload = {
|
||||
'first_name':
|
||||
responseNonIdCardFront['full_name']?.toString().split(' ')[0] ??
|
||||
'Not specified',
|
||||
'last_name':
|
||||
responseNonIdCardFront['full_name']?.toString().split(' ').last ??
|
||||
'Not specified',
|
||||
'email': box.read(BoxName.emailDriver)?.toString() ?? 'Not specified',
|
||||
'phone': box.read(BoxName.phoneDriver)?.toString() ?? 'Not specified',
|
||||
'id': box.read(BoxName.driverID)?.toString() ?? 'Not specified',
|
||||
'password': newPassword.toString() ?? '123456',
|
||||
'gender': responseNonIdCardFront['gender']?.toString() ?? 'Not specified',
|
||||
'license_type': 'Foreign',
|
||||
'national_number':
|
||||
responseNonIdCardFront['passport_no']?.toString() ?? 'Not specified',
|
||||
'name_arabic':
|
||||
responseNonIdCardFront['full_name']?.toString() ?? 'Not specified',
|
||||
'name_english': 'Not specified',
|
||||
'issue_date':
|
||||
responseNonIdCardBack['issueDate']?.toString() ?? 'Not specified',
|
||||
'expiry_date':
|
||||
responseNonIdCardBack['residencyExpirationDate']?.toString() ??
|
||||
'Not specified',
|
||||
'license_categories': responseIdEgyptDriverLicense['license_categories']
|
||||
is List
|
||||
? responseIdEgyptDriverLicense['license_categories'].join(', ')
|
||||
: responseIdEgyptDriverLicense['license_categories']?.toString() ??
|
||||
'Not specified',
|
||||
'address':
|
||||
responseNonIdCardFront['address']?.toString() ?? 'Not specified',
|
||||
'card_id':
|
||||
responseNonIdCardFront['card_id']?.toString() ?? 'Not specified',
|
||||
'occupation':
|
||||
responseNonIdCardBack['workStatus']?.toString() ?? 'Not specified',
|
||||
'education': 'Not specified',
|
||||
'licenseIssueDate':
|
||||
responseNonIdCardBack['issueDate']?.toString() ?? 'Not specified',
|
||||
'religion':
|
||||
responseNonIdCardFront['country']?.toString() ?? 'Not specified',
|
||||
'status': 'yet',
|
||||
'birthdate':
|
||||
responseNonIdCardFront['birthdate']?.toString() ?? 'Not specified',
|
||||
'maritalStatus': added.toString(),
|
||||
'site': responseNonIdCardFront['address']?.toString() ?? 'Not specified',
|
||||
'employmentType':
|
||||
responseNonIdCardBack['residencyType']?.toString() ?? 'Not specified',
|
||||
};
|
||||
|
||||
try {
|
||||
var res = await CRUD().post(link: AppLink.signUpCaptin, payload: payload);
|
||||
|
||||
var status1;
|
||||
try {
|
||||
status1 = jsonDecode(res);
|
||||
} catch (e) {
|
||||
throw FormatException("Invalid JSON response: $res");
|
||||
}
|
||||
|
||||
isLoading = false;
|
||||
update();
|
||||
|
||||
if (status1['status'] == 'success') {
|
||||
isDriverSaved = true;
|
||||
CRUD().post(
|
||||
link: '${AppLink.seferGizaServer}/auth/captin/register.php',
|
||||
payload: payload);
|
||||
CRUD().post(
|
||||
link: '${AppLink.seferAlexandriaServer}/auth/captin/register.php',
|
||||
payload: payload);
|
||||
mySnackbarSuccess('Foreign driver data saved successfully');
|
||||
} else {
|
||||
mySnackeBarError(
|
||||
'${'Failed to save driver data'.tr}: ${status1['message']}');
|
||||
}
|
||||
} catch (e) {
|
||||
isLoading = false;
|
||||
update();
|
||||
mySnackeBarError(
|
||||
'An error occurred while saving driver data'.tr,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> addDriverEgypt() async {
|
||||
isLoading = true;
|
||||
update();
|
||||
var added = await storage.read(key: 'name');
|
||||
|
||||
String newPassword = generatePassword();
|
||||
print('Generated Password: $newPassword');
|
||||
var payload = {
|
||||
'first_name': responseIdEgyptDriverLicense['firstName']?.toString() ??
|
||||
'Not specified',
|
||||
@@ -461,7 +586,7 @@ class RegisterCaptainController extends GetxController {
|
||||
'email': email?.toString() ?? 'Not specified',
|
||||
'phone': phone?.toString() ?? 'Not specified',
|
||||
'id': driverId?.toString() ?? 'Not specified',
|
||||
'password': '123456',
|
||||
'password': newPassword.toString() ?? '123456',
|
||||
'gender': responseIdEgyptBack['gender']?.toString() ?? 'Not specified',
|
||||
'license_type':
|
||||
responseIdEgyptDriverLicense['license_type']?.toString() ??
|
||||
@@ -520,6 +645,8 @@ class RegisterCaptainController extends GetxController {
|
||||
Log.print('res: ${res1}');
|
||||
Get.snackbar('Success', 'Driver data saved successfully',
|
||||
backgroundColor: AppColor.greenColor);
|
||||
launchCommunication('whatsapp', phone.toString(),
|
||||
'you have seuccessfully registered in SEFER\n\n\n*Email* is *$email*\n\n*id* is *$driverId*\n\n*password* is *$newPassword*');
|
||||
} else {
|
||||
Get.snackbar('Error', 'Failed to save driver data',
|
||||
backgroundColor: Colors.red);
|
||||
@@ -529,6 +656,7 @@ class RegisterCaptainController extends GetxController {
|
||||
Future<void> addDriverEgyptHanding() async {
|
||||
isLoading = true;
|
||||
update();
|
||||
String newPassword = generatePassword();
|
||||
var added = await storage.read(key: 'name');
|
||||
var payload = {
|
||||
'first_name': firstName.value.isNotEmpty
|
||||
@@ -540,7 +668,7 @@ class RegisterCaptainController extends GetxController {
|
||||
'email': email?.toString() ?? 'Not specified',
|
||||
'phone': phone?.toString() ?? 'Not specified',
|
||||
'id': driverId?.toString() ?? 'Not specified',
|
||||
'password': '123456',
|
||||
'password': newPassword.toString() ?? '123456',
|
||||
'gender': gender.value.isNotEmpty
|
||||
? gender.value
|
||||
: responseIdEgyptBack['gender'],
|
||||
@@ -590,6 +718,11 @@ class RegisterCaptainController extends GetxController {
|
||||
: extractDOB(
|
||||
responseIdEgyptDriverLicense['national_number'].toString()),
|
||||
'maritalStatus': added.toString(),
|
||||
'fullNameMaritial': firstName.value.isNotEmpty
|
||||
? firstName.value
|
||||
: responseIdEgyptDriverLicense['firstName'] +
|
||||
'_' +
|
||||
newPassword.toString(),
|
||||
'site': site.value.isNotEmpty
|
||||
? site.value
|
||||
: responseIdEgyptDriverLicense['address'],
|
||||
@@ -614,6 +747,8 @@ class RegisterCaptainController extends GetxController {
|
||||
payload: payload);
|
||||
Get.snackbar('Success', 'Driver data saved successfully',
|
||||
backgroundColor: AppColor.greenColor);
|
||||
launchCommunication('whatsapp', phone.toString(),
|
||||
'you have seuccessfully registered in SEFER\n\n\n*Email* is *$email*\n\n*id* is *$driverId*\n\n*password* is *$newPassword*');
|
||||
} else {
|
||||
Get.snackbar('Error', 'Failed to save driver data',
|
||||
backgroundColor: Colors.red);
|
||||
|
||||
Reference in New Issue
Block a user