add country-specific field config to review page, add warning snackbar, write AI extraction prompt
This commit is contained in:
@@ -6,6 +6,7 @@ import 'package:siro_service/constant/box_name.dart';
|
||||
import 'package:siro_service/constant/links.dart';
|
||||
import 'package:siro_service/controller/functions/crud.dart';
|
||||
import 'package:siro_service/main.dart';
|
||||
import 'package:siro_service/views/widgets/mycircular.dart';
|
||||
|
||||
class ReviewDriverController extends GetxController {
|
||||
var isLoading = true.obs;
|
||||
@@ -48,6 +49,189 @@ class ReviewDriverController extends GetxController {
|
||||
'profile_picture': Icons.person,
|
||||
};
|
||||
|
||||
var country = ''.obs;
|
||||
var countryDetected = false;
|
||||
|
||||
/// Get current country code from box or server data
|
||||
String get currentCountry {
|
||||
if (country.value.isNotEmpty) return country.value;
|
||||
final boxCountry = box.read('countryCode')?.toString() ?? '';
|
||||
if (boxCountry.isNotEmpty) {
|
||||
country.value = boxCountry;
|
||||
return boxCountry;
|
||||
}
|
||||
final site = serverData['site'] ?? '';
|
||||
if (site.contains('سوريا') || site.contains('دمشق') || site.contains('حلب')) {
|
||||
country.value = 'Syria';
|
||||
return 'Syria';
|
||||
}
|
||||
if (site.contains('أردن') || site.contains('عمان') || site.contains('اربد')) {
|
||||
country.value = 'Jordan';
|
||||
return 'Jordan';
|
||||
}
|
||||
country.value = 'Syria';
|
||||
return 'Syria';
|
||||
}
|
||||
|
||||
/// Field configuration: which fields appear on which tab, per country
|
||||
/// Each entry: [key, label, isDate, isGender, isColor, isFuel]
|
||||
static final Map<String, Map<String, List<List<dynamic>>>> countryFieldConfig = {
|
||||
'Syria': {
|
||||
'id_front': [
|
||||
['firstNameController', 'First Name', false, false, false, false],
|
||||
['lastNameController', 'Last Name', false, false, false, false],
|
||||
['fatherNameController', 'Father Name', false, false, false, false],
|
||||
['motherNameController', 'Mother Name', false, false, false, false],
|
||||
['nationalNumberController', 'National Number', false, false, false, false],
|
||||
['gender', 'Gender', false, true, false, false],
|
||||
['birthdateController', 'Birthdate', true, false, false, false],
|
||||
['birthPlaceController', 'Birth Place', false, false, false, false],
|
||||
['bloodTypeController', 'Blood Type', false, false, false, false],
|
||||
],
|
||||
'id_back': [
|
||||
['addressController', 'Address', false, false, false, false],
|
||||
['governorateController', 'Governorate', false, false, false, false],
|
||||
['siteController', 'Place of Registration', false, false, false, false],
|
||||
['maritalStatusController', 'Marital Status', false, false, false, false],
|
||||
['spouseNameController', 'Spouse Name', false, false, false, false],
|
||||
['idIssueDateController', 'ID Issue Date', true, false, false, false],
|
||||
['idExpiryDateController', 'ID Expiry Date', true, false, false, false],
|
||||
],
|
||||
'driver_license': [
|
||||
['licenseNumberController', 'License Number', false, false, false, false],
|
||||
['licenseCategoryController', 'License Category', false, false, false, false],
|
||||
['licenseTypeController', 'License Type', false, false, false, false],
|
||||
['licenseIssueDateController', 'Issue Date', true, false, false, false],
|
||||
['expiryDateController', 'Expiry Date', true, false, false, false],
|
||||
],
|
||||
'driver_license_back': [
|
||||
['restrictionsController', 'Restrictions', false, false, false, false],
|
||||
],
|
||||
'car_license_front': [
|
||||
['ownerController', 'Owner Name', false, false, false, false],
|
||||
['carPlateController', 'Car Plate', false, false, false, false],
|
||||
['makeController', 'Make', false, false, false, false],
|
||||
['modelController', 'Model', false, false, false, false],
|
||||
['yearController', 'Year', false, false, false, false],
|
||||
['color', 'Car Color', false, false, true, false],
|
||||
],
|
||||
'car_license_back': [
|
||||
['vinController', 'VIN / Chassis', false, false, false, false],
|
||||
['fuel', 'Fuel Type', false, false, false, true],
|
||||
['engineCapacityController', 'Engine Capacity', false, false, false, false],
|
||||
['carLicenseExpiryDateController', 'License Expiry', true, false, false, false],
|
||||
],
|
||||
'criminal_record': [],
|
||||
'profile_picture': [
|
||||
['phoneController', 'Phone Number', false, false, false, false],
|
||||
['emailController', 'Email', false, false, false, false],
|
||||
],
|
||||
},
|
||||
'Jordan': {
|
||||
'id_front': [
|
||||
['firstNameController', 'First Name', false, false, false, false],
|
||||
['lastNameController', 'Last Name', false, false, false, false],
|
||||
['nationalNumberController', 'National Number', false, false, false, false],
|
||||
['gender', 'Gender', false, true, false, false],
|
||||
['birthdateController', 'Birthdate', true, false, false, false],
|
||||
['siteController', 'Place of Registration', false, false, false, false],
|
||||
['governorateController', 'Governorate', false, false, false, false],
|
||||
],
|
||||
'id_back': [
|
||||
['addressController', 'Address', false, false, false, false],
|
||||
['idIssueDateController', 'ID Issue Date', true, false, false, false],
|
||||
['idExpiryDateController', 'ID Expiry Date', true, false, false, false],
|
||||
['bloodTypeController', 'Blood Type', false, false, false, false],
|
||||
['maritalStatusController', 'Marital Status', false, false, false, false],
|
||||
['spouseNameController', 'Spouse Name', false, false, false, false],
|
||||
['occupationController', 'Occupation', false, false, false, false],
|
||||
],
|
||||
'driver_license': [
|
||||
['licenseNumberController', 'License Number', false, false, false, false],
|
||||
['licenseCategoryController', 'License Category', false, false, false, false],
|
||||
['licenseIssueDateController', 'Issue Date', true, false, false, false],
|
||||
['expiryDateController', 'Expiry Date', true, false, false, false],
|
||||
],
|
||||
'driver_license_back': [
|
||||
['restrictionsController', 'Restrictions', false, false, false, false],
|
||||
],
|
||||
'car_license_front': [
|
||||
['ownerController', 'Owner Name', false, false, false, false],
|
||||
['carPlateController', 'Car Plate', false, false, false, false],
|
||||
['makeController', 'Make', false, false, false, false],
|
||||
['modelController', 'Model', false, false, false, false],
|
||||
['yearController', 'Year', false, false, false, false],
|
||||
['color', 'Car Color', false, false, true, false],
|
||||
],
|
||||
'car_license_back': [
|
||||
['vinController', 'VIN / Chassis', false, false, false, false],
|
||||
['fuel', 'Fuel Type', false, false, false, true],
|
||||
['engineCapacityController', 'Engine Capacity', false, false, false, false],
|
||||
['passengerCapacityController', 'Passenger Capacity', false, false, false, false],
|
||||
['carLicenseExpiryDateController', 'License Expiry', true, false, false, false],
|
||||
],
|
||||
'criminal_record': [],
|
||||
'profile_picture': [
|
||||
['phoneController', 'Phone Number', false, false, false, false],
|
||||
['emailController', 'Email', false, false, false, false],
|
||||
],
|
||||
},
|
||||
'Egypt': {
|
||||
'id_front': [
|
||||
['firstNameController', 'First Name', false, false, false, false],
|
||||
['lastNameController', 'Last Name', false, false, false, false],
|
||||
['nationalNumberController', 'National Number', false, false, false, false],
|
||||
['gender', 'Gender', false, true, false, false],
|
||||
['birthdateController', 'Birthdate', true, false, false, false],
|
||||
['governorateController', 'Governorate', false, false, false, false],
|
||||
],
|
||||
'id_back': [
|
||||
['addressController', 'Address', false, false, false, false],
|
||||
['idIssueDateController', 'ID Issue Date', true, false, false, false],
|
||||
['idExpiryDateController', 'ID Expiry Date', true, false, false, false],
|
||||
['occupationController', 'Occupation', false, false, false, false],
|
||||
['maritalStatusController', 'Marital Status', false, false, false, false],
|
||||
['religionController', 'Religion', false, false, false, false],
|
||||
['bloodTypeController', 'Blood Type', false, false, false, false],
|
||||
['spouseNameController', 'Spouse Name', false, false, false, false],
|
||||
],
|
||||
'driver_license': [
|
||||
['licenseNumberController', 'License Number', false, false, false, false],
|
||||
['licenseCategoryController', 'License Category', false, false, false, false],
|
||||
['licenseIssueDateController', 'Issue Date', true, false, false, false],
|
||||
['expiryDateController', 'Expiry Date', true, false, false, false],
|
||||
],
|
||||
'driver_license_back': [
|
||||
['restrictionsController', 'Restrictions', false, false, false, false],
|
||||
],
|
||||
'car_license_front': [
|
||||
['ownerController', 'Owner Name', false, false, false, false],
|
||||
['carPlateController', 'Car Plate', false, false, false, false],
|
||||
['makeController', 'Make', false, false, false, false],
|
||||
['modelController', 'Model', false, false, false, false],
|
||||
['yearController', 'Year', false, false, false, false],
|
||||
['color', 'Car Color', false, false, true, false],
|
||||
],
|
||||
'car_license_back': [
|
||||
['vinController', 'VIN / Chassis', false, false, false, false],
|
||||
['fuel', 'Fuel Type', false, false, false, true],
|
||||
['engineCapacityController', 'Engine Capacity', false, false, false, false],
|
||||
['carLicenseExpiryDateController', 'License Expiry', true, false, false, false],
|
||||
],
|
||||
'criminal_record': [],
|
||||
'profile_picture': [
|
||||
['phoneController', 'Phone Number', false, false, false, false],
|
||||
['emailController', 'Email', false, false, false, false],
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
List<List<dynamic>> getFieldsForTab(String tabKey) {
|
||||
final c = currentCountry;
|
||||
final config = countryFieldConfig[c] ?? countryFieldConfig['Syria']!;
|
||||
return config[tabKey] ?? [];
|
||||
}
|
||||
|
||||
late TextEditingController firstNameController;
|
||||
late TextEditingController lastNameController;
|
||||
late TextEditingController phoneController;
|
||||
@@ -67,6 +251,22 @@ class ReviewDriverController extends GetxController {
|
||||
late TextEditingController makeController;
|
||||
late TextEditingController modelController;
|
||||
late TextEditingController yearController;
|
||||
late TextEditingController fatherNameController;
|
||||
late TextEditingController motherNameController;
|
||||
late TextEditingController birthPlaceController;
|
||||
late TextEditingController bloodTypeController;
|
||||
late TextEditingController maritalStatusController;
|
||||
late TextEditingController spouseNameController;
|
||||
late TextEditingController idIssueDateController;
|
||||
late TextEditingController idExpiryDateController;
|
||||
late TextEditingController licenseNumberController;
|
||||
late TextEditingController licenseCategoryController;
|
||||
late TextEditingController restrictionsController;
|
||||
late TextEditingController governorateController;
|
||||
late TextEditingController occupationController;
|
||||
late TextEditingController religionController;
|
||||
late TextEditingController engineCapacityController;
|
||||
late TextEditingController passengerCapacityController;
|
||||
|
||||
var selectedGender = ''.obs;
|
||||
var colorHex = ''.obs;
|
||||
@@ -105,6 +305,22 @@ class ReviewDriverController extends GetxController {
|
||||
makeController = TextEditingController();
|
||||
modelController = TextEditingController();
|
||||
yearController = TextEditingController();
|
||||
fatherNameController = TextEditingController();
|
||||
motherNameController = TextEditingController();
|
||||
birthPlaceController = TextEditingController();
|
||||
bloodTypeController = TextEditingController();
|
||||
maritalStatusController = TextEditingController();
|
||||
spouseNameController = TextEditingController();
|
||||
idIssueDateController = TextEditingController();
|
||||
idExpiryDateController = TextEditingController();
|
||||
licenseNumberController = TextEditingController();
|
||||
licenseCategoryController = TextEditingController();
|
||||
restrictionsController = TextEditingController();
|
||||
governorateController = TextEditingController();
|
||||
occupationController = TextEditingController();
|
||||
religionController = TextEditingController();
|
||||
engineCapacityController = TextEditingController();
|
||||
passengerCapacityController = TextEditingController();
|
||||
}
|
||||
|
||||
Future<void> fetchData() async {
|
||||
@@ -124,7 +340,7 @@ class ReviewDriverController extends GetxController {
|
||||
_populateDocUrls(raw['documents']);
|
||||
}
|
||||
} catch (e) {
|
||||
Get.snackbar('Error', 'Failed to load data: $e');
|
||||
mySnackeBarError('Failed to load data: $e');
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
@@ -168,6 +384,39 @@ class ReviewDriverController extends GetxController {
|
||||
modelController.text = serverData['model'] ?? '';
|
||||
yearController.text = serverData['year'] ?? '';
|
||||
selectedFuel.value = serverData['fuel'] ?? '';
|
||||
fatherNameController.text = serverData['father_name'] ?? '';
|
||||
motherNameController.text = serverData['mother_name'] ?? '';
|
||||
birthPlaceController.text = serverData['birth_place'] ?? '';
|
||||
bloodTypeController.text = serverData['blood_type'] ?? '';
|
||||
maritalStatusController.text = serverData['marital_status'] ?? '';
|
||||
spouseNameController.text = serverData['spouse_name'] ?? '';
|
||||
idIssueDateController.text = serverData['id_issue_date'] ?? '';
|
||||
idExpiryDateController.text = serverData['id_expiry_date'] ?? '';
|
||||
licenseNumberController.text = serverData['license_number'] ?? '';
|
||||
licenseCategoryController.text = serverData['license_category'] ?? '';
|
||||
restrictionsController.text = serverData['restrictions'] ?? '';
|
||||
governorateController.text = serverData['governorate'] ?? '';
|
||||
occupationController.text = serverData['occupation'] ?? '';
|
||||
religionController.text = serverData['religion'] ?? '';
|
||||
engineCapacityController.text = serverData['engine_capacity'] ?? '';
|
||||
passengerCapacityController.text = serverData['passenger_capacity'] ?? '';
|
||||
|
||||
// Detect country from server data if available
|
||||
if (!countryDetected) {
|
||||
countryDetected = true;
|
||||
if (serverData['country']?.isNotEmpty == true) {
|
||||
country.value = serverData['country']!;
|
||||
} else if (serverData['site']?.isNotEmpty == true) {
|
||||
final s = serverData['site']!;
|
||||
if (s.contains('سوريا') || s.contains('دمشق')) {
|
||||
country.value = 'Syria';
|
||||
} else if (s.contains('أردن') || s.contains('عمان')) {
|
||||
country.value = 'Jordan';
|
||||
} else if (s.contains('مصر') || s.contains('القاهرة')) {
|
||||
country.value = 'Egypt';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final serverColorName = serverData['color'] ?? '';
|
||||
final colorOption = kCarColorOptions.firstWhere(
|
||||
@@ -264,12 +513,12 @@ class ReviewDriverController extends GetxController {
|
||||
payload: payload,
|
||||
);
|
||||
if (response != 'failure' && response['status'] == 'success') {
|
||||
Get.snackbar('Success', 'Data saved successfully');
|
||||
mySnackbarSuccess('Data saved successfully');
|
||||
} else {
|
||||
Get.snackbar('Error', 'Failed to save changes');
|
||||
mySnackeBarError('Failed to save changes');
|
||||
}
|
||||
} catch (e) {
|
||||
Get.snackbar('Error', 'Error: $e');
|
||||
mySnackeBarError('Error: $e');
|
||||
} finally {
|
||||
isSaving.value = false;
|
||||
}
|
||||
@@ -284,14 +533,14 @@ class ReviewDriverController extends GetxController {
|
||||
payload: payload,
|
||||
);
|
||||
if (response != 'failure' && response['status'] == 'success') {
|
||||
Get.snackbar('Success', 'Driver activated successfully!');
|
||||
mySnackbarSuccess('Driver activated successfully!');
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
Get.back();
|
||||
} else {
|
||||
Get.snackbar('Error', 'Failed to activate driver');
|
||||
mySnackeBarError('Failed to activate driver');
|
||||
}
|
||||
} catch (e) {
|
||||
Get.snackbar('Error', 'Error: $e');
|
||||
mySnackeBarError('Error: $e');
|
||||
} finally {
|
||||
isSaving.value = false;
|
||||
}
|
||||
@@ -299,7 +548,7 @@ class ReviewDriverController extends GetxController {
|
||||
|
||||
Future<void> rejectDriver(String reason) async {
|
||||
if (reason.trim().isEmpty) {
|
||||
Get.snackbar('Error', 'Please enter a rejection reason');
|
||||
mySnackeBarError('Please enter a rejection reason');
|
||||
return;
|
||||
}
|
||||
isSaving.value = true;
|
||||
@@ -312,14 +561,14 @@ class ReviewDriverController extends GetxController {
|
||||
},
|
||||
);
|
||||
if (response != 'failure' && response['status'] == 'success') {
|
||||
Get.snackbar('Success', 'Driver rejected');
|
||||
mySnackbarSuccess('Driver rejected');
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
Get.back();
|
||||
} else {
|
||||
Get.snackbar('Error', 'Failed to reject driver');
|
||||
mySnackeBarError('Failed to reject driver');
|
||||
}
|
||||
} catch (e) {
|
||||
Get.snackbar('Error', 'Error: $e');
|
||||
mySnackeBarError('Error: $e');
|
||||
} finally {
|
||||
isSaving.value = false;
|
||||
}
|
||||
@@ -414,6 +663,22 @@ class ReviewDriverController extends GetxController {
|
||||
makeController.dispose();
|
||||
modelController.dispose();
|
||||
yearController.dispose();
|
||||
fatherNameController.dispose();
|
||||
motherNameController.dispose();
|
||||
birthPlaceController.dispose();
|
||||
bloodTypeController.dispose();
|
||||
maritalStatusController.dispose();
|
||||
spouseNameController.dispose();
|
||||
idIssueDateController.dispose();
|
||||
idExpiryDateController.dispose();
|
||||
licenseNumberController.dispose();
|
||||
licenseCategoryController.dispose();
|
||||
restrictionsController.dispose();
|
||||
governorateController.dispose();
|
||||
occupationController.dispose();
|
||||
religionController.dispose();
|
||||
engineCapacityController.dispose();
|
||||
passengerCapacityController.dispose();
|
||||
super.onClose();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user