@@ -1,6 +1,11 @@
import ' dart:convert ' ;
import ' dart:io ' ;
import ' package:SEFER/constant/box_name.dart ' ;
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:flutter/material.dart ' ;
import ' package:get/get.dart ' ;
import ' package:image_cropper/image_cropper.dart ' ;
import ' package:image_picker/image_picker.dart ' ;
@@ -10,17 +15,270 @@ import 'package:path_provider/path_provider.dart';
import ' ../../constant/api_key.dart ' ;
import ' ../../constant/colors.dart ' ;
import ' tts.dart ' ;
import ' upload_image.dart ' ;
class AI extends GetxController {
bool approved = false ;
void setApproved ( ) {
approved = true ;
update ( ) ;
}
final today = DateTime . now ( ) ;
Future < void > addDriverAndCarEgypt ( ) async {
final expiryDate = responseIdEgyptDriverLicense [ ' expiry_date ' ] ;
final expiryDateTime = DateTime . tryParse ( expiryDate ) ;
final isExpired = expiryDateTime ! = null & & expiryDateTime . isBefore ( today ) ;
final taxExpiryDate = responseIdCardDriverEgyptBack [ ' tax_expiry ' ] ;
// Get the inspection date from the response
final inspectionDate = responseIdCardDriverEgyptBack [ ' inspection_date ' ] ;
// Try parsing the tax expiry date. If it fails, set it to null.
final taxExpiryDateTime = DateTime . tryParse ( taxExpiryDate ? ? ' ' ) ;
final isExpiredCar =
taxExpiryDateTime ! = null & & taxExpiryDateTime . isBefore ( today ) ;
// Check if the inspection date is before today
final inspectionDateTime = DateTime ( int . parse ( inspectionDate ? ? ' ' ) , 1 , 1 ) ;
final isInspectionExpired = inspectionDateTime . isBefore ( today ) ;
if ( isExpiredCar | | isInspectionExpired ) {
Get . defaultDialog (
title: ' Expired Driver’ s License ' . tr ,
content: Column (
mainAxisSize: MainAxisSize . min ,
children: [
const Icon ( Icons . warning , size: 48 , color: Colors . red ) ,
const SizedBox ( height: 16 ) ,
Text (
' Your driver’ s license and/or car tax has expired. Please renew them before proceeding. '
. tr ,
textAlign: TextAlign . center ,
style: AppStyle . title ,
) ,
const SizedBox ( height: 16 ) ,
IconButton (
onPressed: ( ) async {
await Get . find < TextToSpeechController > ( ) . speakText (
' Your driver’ s license and/or car tax has expired. Please renew them before proceeding. '
. tr ,
) ;
} ,
icon: const Icon ( Icons . volume_up ) ,
) ,
] ,
) ,
actions: [
TextButton (
onPressed: ( ) {
Get . back ( ) ;
} ,
child: const Text ( ' OK ' ) ,
) ,
] ,
) ;
} else if ( isExpired ) {
Get . defaultDialog (
title: ' Expired Driver’ s License ' . tr ,
content: Column (
mainAxisSize: MainAxisSize . min ,
children: [
const Icon ( Icons . warning , size: 48 , color: Colors . red ) ,
const SizedBox ( height: 16 ) ,
Text (
' Your driver’ s license has expired. Please renew it before proceeding. '
. tr ,
textAlign: TextAlign . center ,
style: AppStyle . title ,
) ,
const SizedBox ( height: 16 ) ,
IconButton (
onPressed: ( ) async {
await Get . find < TextToSpeechController > ( ) . speakText (
' Your driver’ s license has expired. Please renew it before proceeding. '
. tr ,
) ;
} ,
icon: const Icon ( Icons . volume_up ) ,
) ,
] ,
) ,
actions: [
TextButton (
onPressed: ( ) {
Get . back ( ) ;
} ,
child: const Text ( ' OK ' ) ,
) ,
] ,
) ;
} else if ( responseIdEgyptDriverLicense [ ' national_number ' ] ! =
responseIdEgyptBack [ ' nationalID ' ] ) {
Get . defaultDialog (
barrierDismissible: false ,
title: ' ID Mismatch ' ,
content: Column (
mainAxisSize: MainAxisSize . min ,
children: [
const Icon ( Icons . warning , size: 48 , color: Colors . red ) ,
const SizedBox ( height: 16 ) ,
Text (
' The national number on your driver’ s license does not match the one on your ID document. Please verify and provide the correct documents. '
. tr ,
textAlign: TextAlign . center ,
style: AppStyle . title ,
) ,
const SizedBox ( height: 16 ) ,
IconButton (
onPressed: ( ) async {
await Get . find < TextToSpeechController > ( ) . speakText (
' The national number on your driver’ s license does not match the one on your ID document. Please verify and provide the correct documents. ' ,
) ;
} ,
icon: const Icon ( Icons . volume_up ) ,
) ,
] ,
) ,
actions: [
TextButton (
onPressed: ( ) {
Get . back ( ) ;
} ,
child: const Text ( ' OK ' ) ,
) ,
] ,
) ;
} else if ( responseCriminalRecordEgypt [ ' FullName ' ] ! =
responseIdEgyptDriverLicense [ ' name_arabic ' ] ) {
Get . defaultDialog (
barrierDismissible: false ,
title: ' Criminal Record Mismatch ' ,
content: Column (
mainAxisSize: MainAxisSize . min ,
children: [
const Icon ( Icons . warning , size: 48 , color: Colors . red ) ,
const SizedBox ( height: 16 ) ,
Text (
' The full name on your criminal record does not match the one on your driver’ s license. Please verify and provide the correct documents. '
. tr ,
textAlign: TextAlign . center ,
style: AppStyle . title ,
) ,
const SizedBox ( height: 16 ) ,
IconButton (
onPressed: ( ) async {
await Get . find < TextToSpeechController > ( ) . speakText (
' The full name on your criminal record does not match the one on your driver’ s license. Please verify and provide the correct documents. '
. tr ,
) ;
} ,
icon: const Icon ( Icons . volume_up ) ,
) ,
] ,
) ,
actions: [
TextButton (
onPressed: ( ) {
Get . back ( ) ;
} ,
child: const Text ( ' OK ' ) ,
) ,
] ,
) ;
} else {
isLoading = true ;
update ( ) ;
await addDriverEgypt ( ) ;
await addRegistrationCarEgypt ( ) ;
isLoading = false ;
update ( ) ;
}
}
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 ' ,
backgroundColor: AppColor . greenColor ) ;
}
} catch ( e ) {
print ( ' error is $ e ' ) ;
}
}
Future addRegistrationCarEgypt ( ) async {
try {
var res = await CRUD ( ) . post ( link: AppLink . addRegisrationCar , payload: {
' driverID ' : box . read ( BoxName . driverID ) ,
' vin ' : responseIdCardDriverEgyptBack [ ' chassis ' ] . toString ( ) ,
' car_plate ' : responseIdCardDriverEgyptFront [ ' car_plate ' ] . toString ( ) ,
' make ' : responseIdCardDriverEgyptBack [ ' make ' ] . toString ( ) ,
' model ' : responseIdCardDriverEgyptBack [ ' model ' ] ,
' year ' : responseIdCardDriverEgyptBack [ ' year ' ] . toString ( ) ,
' expiration_date ' :
responseIdCardDriverEgyptFront [ ' LicenseExpirationDate ' ] . toString ( ) ,
' color ' : responseIdCardDriverEgyptBack [ ' color ' ] ,
' owner ' : responseIdCardDriverEgyptFront [ ' owner ' ] ,
' color_hex ' : responseIdCardDriverEgyptBack [ ' color_hex ' ] . toString ( ) ,
' address ' : responseIdCardDriverEgyptFront [ ' address ' ] . toString ( ) ,
' displacement ' : responseIdCardDriverEgyptBack [ ' engine ' ] . toString ( ) ,
' fuel ' : responseIdCardDriverEgyptBack [ ' fuel ' ] . toString ( ) ,
' registration_date ' :
' ${ responseIdCardDriverEgyptBack [ ' inspection_date ' ] } -01-01 ' ,
} ) ;
var status = jsonDecode ( res ) ;
if ( status = = ' success ' ) {
Get . snackbar ( ' Success ' , ' message ' ,
backgroundColor: AppColor . greenColor ) ;
}
} catch ( e ) {
print ( ' error is $ e ' ) ;
}
}
final picker = ImagePicker ( ) ;
Map < String , dynamic > responseMap = { } ;
Map < String , dynamic > responseCarLicenseMap = { } ;
Map < String , dynamic > responseCarLicenseMapJordan = { } ;
Map < String , dynamic > responseBackCarLicenseMap = { } ;
Map < String , dynamic > responseIdCardMap = { } ;
Map < String , dynamic > responseIdCardDriverEgyptBack = { } ;
Map < String , dynamic > responseIdCardDriverEgyptFront = { } ;
Map < String , dynamic > responseIdEgyptFront = { } ;
Map < String , dynamic > responseCriminalRecordEgypt = { } ;
Map < String , dynamic > responseIdEgyptBack = { } ;
Map < String , dynamic > responseIdEgyptDriverLicense = { } ;
String ? responseIdCardDriverEgypt1 ;
@@ -87,7 +345,7 @@ class AI extends GetxController {
var json = jsonDecode ( extractedString ) ;
var textValues = CRUD ( ) . extractTextFromLines ( json ) ;
print ( textValues ) ;
// await Get.put(AI()).geminiAiExtraction(prompt, textValues);
// await Get.put(AI()).geminiAiExtraction(prompt, textValues, imagePath );
await Get . put ( AI ( ) ) . anthropicAI ( textValues , prompt , imagePath ) ;
isLoading = false ;
update ( ) ;
@@ -238,6 +496,10 @@ class AI extends GetxController {
responseIdEgyptDriverLicense =
jsonDecode ( responseData [ ' content ' ] [ 0 ] [ ' text ' ] ) ;
print ( responseIdEgyptDriverLicense ) ;
} else if ( idType = = ' criminalRecord ' ) {
responseCriminalRecordEgypt =
jsonDecode ( responseData [ ' content ' ] [ 0 ] [ ' text ' ] ) ;
print ( responseCriminalRecordEgypt ) ;
}
update ( ) ;
@@ -246,7 +508,7 @@ class AI extends GetxController {
return responseIdCardDriverEgyptBack . toString ( ) ;
}
Future < void > geminiAiExtraction ( String prompt , payload ) async {
Future < void > geminiAiExtraction ( String prompt , payload , String idType ) async {
var requestBody = jsonEncode ( {
" contents " : [
{
@@ -309,11 +571,28 @@ class AI extends GetxController {
// Convert the JSON object to a String
jsonString = jsonEncode ( json . decode ( jsonString ) ) ;
responseIdCardDriverEgyptBack = jsonDecode ( jsonString ) ;
print ( responseIdCardDriverEgyptBack ) ;
if ( idType = = ' car_back ' ) {
responseIdCardDriverEgyptBack = jsonDecode ( jsonString ) ;
print ( responseIdCardDriverEgyptBack ) ;
} else if ( idType = = ' car_front ' ) {
responseIdCardDriverEgyptFront = jsonDecode ( jsonString ) ;
print ( responseIdCardDriverEgyptFront ) ;
} else if ( idType = = ' id_front ' ) {
responseIdEgyptFront = jsonDecode ( jsonString ) ;
print ( responseIdEgyptFront ) ;
} else if ( idType = = ' id_back ' ) {
responseIdEgyptBack = jsonDecode ( jsonString ) ;
print ( responseIdEgyptBack ) ;
} else if ( idType = = ' driver_license ' ) {
responseIdEgyptDriverLicense = jsonDecode ( jsonString ) ;
print ( responseIdEgyptDriverLicense ) ;
}
update ( ) ;
} else {
print ( " JSON string not found " ) ;
Get . snackbar ( ' Error ' , " JSON string not found " ,
backgroundColor: AppColor . redColor ) ;
}
// Rest of your code...
@@ -503,10 +782,10 @@ Output the extracted information in the following JSON format''',
if ( jsonString ! = null ) {
// Convert the JSON object to a String
jsonString = jsonEncode ( json . decode ( jsonString ) ) ;
responseCarLicenseMap = jsonDecode ( jsonString ) ;
responseCarLicenseMapJordan = jsonDecode ( jsonString ) ;
print ( jsonString ) ;
print ( responseCarLicenseMap ) ;
print ( responseCarLicenseMap [ ' plate_number ' ] ) ;
print ( responseCarLicenseMapJordan ) ;
print ( responseCarLicenseMapJordan [ ' plate_number ' ] ) ;
} else {
print ( " JSON string not found " ) ;
}
@@ -604,10 +883,10 @@ Output the extracted information in the following JSON format''',
if ( jsonString ! = null ) {
// Convert the JSON object to a String
jsonString = jsonEncode ( json . decode ( jsonString ) ) ;
responseCarLicenseMap = jsonDecode ( jsonString ) ;
responseCarLicenseMapJordan = jsonDecode ( jsonString ) ;
print ( jsonString ) ;
print ( responseCarLicenseMap ) ;
print ( responseCarLicenseMap [ ' plate_number ' ] ) ;
print ( responseCarLicenseMapJordan ) ;
print ( responseCarLicenseMapJordan [ ' plate_number ' ] ) ;
} else {
print ( " JSON string not found " ) ;
}
@@ -714,10 +993,10 @@ Output the extracted information in the following JSON formate and make date for
if ( jsonString ! = null ) {
// Convert the JSON object to a String
jsonString = jsonEncode ( json . decode ( jsonString ) ) ;
responseCarLicenseMap = jsonDecode ( jsonString ) ;
responseCarLicenseMapJordan = jsonDecode ( jsonString ) ;
print ( jsonString ) ;
print ( responseCarLicenseMap ) ;
print ( responseCarLicenseMap [ ' plate_number ' ] ) ;
print ( responseCarLicenseMapJordan ) ;
print ( responseCarLicenseMapJordan [ ' plate_number ' ] ) ;
} else {
print ( " JSON string not found " ) ;
}