11/19/1
This commit is contained in:
@@ -70,8 +70,8 @@ class CRUD {
|
||||
'Basic ${base64Encode(utf8.encode(AppCredintials.basicAuthCredentials))}',
|
||||
},
|
||||
);
|
||||
// print(response.request);
|
||||
// print(payload);
|
||||
print(response.request);
|
||||
print(payload);
|
||||
|
||||
var jsonData = jsonDecode(response.body);
|
||||
if (response.statusCode == 200) {
|
||||
@@ -80,7 +80,7 @@ class CRUD {
|
||||
jsonData['status'],
|
||||
jsonData['message'],
|
||||
);
|
||||
// print(response.body);
|
||||
print(response.body);
|
||||
return response.body;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
import 'package:camera/camera.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:google_mlkit_text_recognition/google_mlkit_text_recognition.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:path_provider/path_provider.dart' as path_provider;
|
||||
import 'package:ride/constant/box_name.dart';
|
||||
import 'package:ride/constant/colors.dart';
|
||||
import 'package:ride/constant/credential.dart';
|
||||
@@ -15,6 +17,7 @@ import 'package:ride/constant/table_names.dart';
|
||||
import 'package:ride/main.dart';
|
||||
import 'package:ride/views/widgets/elevated_btn.dart';
|
||||
|
||||
import '../../constant/links.dart';
|
||||
import '../../views/auth/captin/car_license_page.dart';
|
||||
import 'launch.dart';
|
||||
|
||||
@@ -229,6 +232,56 @@ class ScanDocumentsByApi extends GetxController {
|
||||
XFile? imageFace;
|
||||
late String imagePath;
|
||||
DateTime now = DateTime.now();
|
||||
late String name;
|
||||
late String licenseClass;
|
||||
late String documentNo;
|
||||
late String address;
|
||||
late String stateCode;
|
||||
late String height;
|
||||
late String sex;
|
||||
late String postalCode;
|
||||
late String dob;
|
||||
late String expireDate;
|
||||
|
||||
// ///////////////////////
|
||||
// late CameraController cameraController;
|
||||
// late List<CameraDescription> cameras;
|
||||
// bool isCameraInitialized = false;
|
||||
// // final TextRecognizer _textRecognizer = TextRecognizer();
|
||||
// String? scannedText;
|
||||
|
||||
// Future<void> initializeCamera(int cameraID) async {
|
||||
// try {
|
||||
// cameras = await availableCameras();
|
||||
// //update();
|
||||
// cameraController = CameraController(
|
||||
// cameras[cameraID],
|
||||
// ResolutionPreset.medium,
|
||||
// enableAudio: false,
|
||||
// );
|
||||
// await cameraController.initialize();
|
||||
// isCameraInitialized = true;
|
||||
// update();
|
||||
// } catch (e) {
|
||||
// if (e is CameraException) {
|
||||
// switch (e.code) {
|
||||
// case 'CameraAccessDenied':
|
||||
// Get.defaultDialog(
|
||||
// title: 'Camera Access Denied.'.tr,
|
||||
// middleText: '',
|
||||
// confirm:
|
||||
// MyElevatedButton(title: 'Open Settings', onPressed: () {}),
|
||||
// );
|
||||
// break;
|
||||
// default:
|
||||
// // Handle other errors here.
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
///
|
||||
|
||||
Future<void> scanDocumentsByApi() async {
|
||||
// Pick an image from the camera or gallery
|
||||
@@ -252,6 +305,17 @@ class ScanDocumentsByApi extends GetxController {
|
||||
if (response.statusCode == 200) {
|
||||
String responseString = await response.stream.bytesToString();
|
||||
responseMap = jsonDecode(responseString);
|
||||
var ocrData = responseMap['data']['ocr'];
|
||||
name = ocrData['name'].toString();
|
||||
licenseClass = ocrData['dlClass'].toString();
|
||||
documentNo = ocrData['documentNumber'].toString();
|
||||
address = ocrData['address'].toString();
|
||||
height = ocrData['height'].toString();
|
||||
postalCode = ocrData['addressPostalCode'].toString();
|
||||
sex = ocrData['sex'].toString();
|
||||
stateCode = ocrData['addressJurisdictionCode'].toString();
|
||||
expireDate = ocrData['dateOfExpiry'].toString();
|
||||
dob = ocrData['dateOfBirth'].toString();
|
||||
if (responseMap['data'] != null &&
|
||||
responseMap['data']['image'] != null &&
|
||||
responseMap['data']['image']['portrait'] != null) {
|
||||
@@ -303,10 +367,9 @@ class ScanDocumentsByApi extends GetxController {
|
||||
} else {
|
||||
if (times < 4) {
|
||||
times++;
|
||||
|
||||
matchFaceApi();
|
||||
sql.updateData(
|
||||
{'faceDetectTimes': times}, TableName.faceDetectTimes, 1);
|
||||
matchFaceApi();
|
||||
} else {
|
||||
Get.defaultDialog(
|
||||
barrierDismissible: false,
|
||||
@@ -366,10 +429,11 @@ class ScanDocumentsByApi extends GetxController {
|
||||
print(res);
|
||||
|
||||
update();
|
||||
res['data']['result'].toString() == 'No face detected in image2'
|
||||
res['data']['result'].toString().contains('No face detected in image')
|
||||
? Get.defaultDialog(
|
||||
barrierDismissible: false,
|
||||
title: 'No face detected'.tr,
|
||||
middleText: ''.tr,
|
||||
titleStyle: AppStyle.title,
|
||||
confirm: MyElevatedButton(
|
||||
kolor: AppColor.yellowColor,
|
||||
@@ -417,12 +481,44 @@ class ScanDocumentsByApi extends GetxController {
|
||||
print(response.reasonPhrase);
|
||||
}
|
||||
}
|
||||
// Todo upload images and fields
|
||||
|
||||
Future<String> uploadImage(File imageFile) async {
|
||||
var request = http.MultipartRequest(
|
||||
'POST',
|
||||
Uri.parse(AppLink.uploadImage),
|
||||
);
|
||||
|
||||
// Attach the image file to the request
|
||||
request.files.add(
|
||||
await http.MultipartFile.fromPath('image', imageFile.path),
|
||||
); // Add the headers to the request
|
||||
request.headers.addAll({
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
'Authorization':
|
||||
'Basic ${base64Encode(utf8.encode(AppCredintials.basicAuthCredentials))}',
|
||||
});
|
||||
|
||||
// Add the driverID to the request
|
||||
request.fields['driverID'] = box.read(BoxName.driverID);
|
||||
// Send the request
|
||||
var response = await request.send();
|
||||
|
||||
// Read the response
|
||||
var responseData = await response.stream.toBytes();
|
||||
var responseString = String.fromCharCodes(responseData);
|
||||
// scannedText = responseString;
|
||||
update();
|
||||
// Return the link received from the server
|
||||
return responseString;
|
||||
}
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
// scanDocumentsByApi();
|
||||
// initializeCamera(0);
|
||||
sql.getAllData(TableName.faceDetectTimes).then((value) {
|
||||
if (value.isEmpty || value == null) {
|
||||
if (value.isEmpty) {
|
||||
print(value);
|
||||
times = 0;
|
||||
print(times);
|
||||
@@ -435,110 +531,7 @@ class ScanDocumentsByApi extends GetxController {
|
||||
super.onInit();
|
||||
}
|
||||
}
|
||||
//
|
||||
// class PassportRecognizerController extends GetxController {
|
||||
// @override
|
||||
// void onInit() {
|
||||
// scanText();
|
||||
// super.onInit();
|
||||
// }
|
||||
//
|
||||
// // The ImagePicker instance
|
||||
// final ImagePicker _imagePicker = ImagePicker();
|
||||
// Map extractedData = {};
|
||||
//
|
||||
// // The GoogleMlKit TextRecognizer instance
|
||||
// final TextRecognizer _textRecognizer = TextRecognizer();
|
||||
//
|
||||
// // The scanned text
|
||||
// String? scannedText;
|
||||
// String? jsonOutput;
|
||||
// final List<Map<String, dynamic>> lines = [];
|
||||
//
|
||||
// Map decode = {};
|
||||
// // Picks an image from the camera or gallery and extracts the text
|
||||
//
|
||||
// Future<void> scanText() async {
|
||||
// // Pick an image from the camera or gallery
|
||||
// final XFile? image =
|
||||
// await _imagePicker.pickImage(source: ImageSource.gallery);
|
||||
//
|
||||
// // If no image was picked, return
|
||||
// if (image == null) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// // Convert the XFile object to an InputImage object
|
||||
// final InputImage inputImage = InputImage.fromFile(File(image.path));
|
||||
//
|
||||
// // Recognize the text in the image
|
||||
// final RecognizedText recognizedText =
|
||||
// await _textRecognizer.processImage(inputImage);
|
||||
// scannedText = recognizedText.text;
|
||||
// // Extract the scanned text line by line
|
||||
// final List<Map<String, dynamic>> lines = [];
|
||||
// for (var i = 0; i < recognizedText.blocks.length; i++) {
|
||||
// lines.add({
|
||||
// i.toString() +
|
||||
// '_' +
|
||||
// recognizedText.blocks[i].text.toString().split('\n')[0]:
|
||||
// recognizedText.blocks[i].text,
|
||||
// });
|
||||
// }
|
||||
// // for (var i = 0; i < recognizedText.blocks.length; i++) {
|
||||
// // final block = recognizedText.blocks[i];
|
||||
// for (final line in lines) {
|
||||
// final key = line.keys.first;
|
||||
// final value = line.values.first;
|
||||
// if (line.values.contains('UNITED STATES OF')) {
|
||||
// final title = line;
|
||||
// extractedData['title'] = title;
|
||||
// }
|
||||
// if (line.values.contains('PASSPORT CARD')) {
|
||||
// final passport = line;
|
||||
// extractedData['passport'] = passport;
|
||||
// }
|
||||
// if (key == "7_Surname") {
|
||||
// final nextItem = lines[lines.indexOf(line) + 1];
|
||||
// extractedData['surname'] = nextItem.values.first;
|
||||
// }
|
||||
// if (key == "6_Nationality") {
|
||||
// var nationality = value.split('\n')[1];
|
||||
// extractedData['nationality'] = nationality;
|
||||
// }
|
||||
// if (key.contains('CARD')) {
|
||||
// var passportCard = value;
|
||||
// extractedData['passportCard'] = passportCard;
|
||||
// }
|
||||
// if (key.contains("9_Given")) {
|
||||
// var givenNames = value.split('\n')[1];
|
||||
// extractedData['givenNames'] = givenNames;
|
||||
// }
|
||||
// if (key.contains("13_Date of Birth")) {
|
||||
// final parts = value.split('\n');
|
||||
// if (parts.length > 1) {
|
||||
// var dateOfBirth = parts[1];
|
||||
// extractedData['dateOfBirth'] = dateOfBirth;
|
||||
//
|
||||
// var sex = parts[0].split(' ')[1];
|
||||
// extractedData['sex'] = sex;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // }
|
||||
// }
|
||||
//
|
||||
// // Convert the list of lines to a JSON string
|
||||
// jsonOutput = jsonEncode(extractedData);
|
||||
// decode = jsonDecode(jsonOutput!);
|
||||
//
|
||||
// update();
|
||||
// print('jsonOutput------------------------------');
|
||||
// print(decode);
|
||||
// // print(jsonEncode(lines));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
|
||||
// class PassportDataExtractor extends GetxController {
|
||||
// @override
|
||||
// void onInit() {
|
||||
|
||||
Reference in New Issue
Block a user