11/1/1
This commit is contained in:
@@ -6,10 +6,12 @@ import 'package:flutter_tesseract_ocr/flutter_tesseract_ocr.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:google_mlkit_text_recognition/google_mlkit_text_recognition.dart';
|
||||
import 'package:ride/constant/box_name.dart';
|
||||
import 'package:ride/constant/credential.dart';
|
||||
import 'package:ride/constant/links.dart';
|
||||
import 'package:ride/views/widgets/elevated_btn.dart';
|
||||
import 'package:path_provider/path_provider.dart' as path_provider;
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
import '../../main.dart';
|
||||
|
||||
class CameraClassController extends GetxController {
|
||||
@@ -32,7 +34,7 @@ class CameraClassController extends GetxController {
|
||||
update();
|
||||
cameraController = CameraController(
|
||||
cameras[0],
|
||||
ResolutionPreset.max,
|
||||
ResolutionPreset.medium,
|
||||
enableAudio: false,
|
||||
);
|
||||
await cameraController.initialize();
|
||||
@@ -57,6 +59,76 @@ class CameraClassController extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
var imgUrl = '';
|
||||
Future extractCardId() async {
|
||||
// Construct the path for the image file
|
||||
final directory = await path_provider.getTemporaryDirectory();
|
||||
final imagePath =
|
||||
path.join(directory.path, '${box.read(BoxName.driverID)}.png');
|
||||
|
||||
// Capture the image and save it to the specified path
|
||||
final XFile capturedImage = await cameraController.takePicture();
|
||||
|
||||
// Move the captured image to the desired path
|
||||
await capturedImage.saveTo(imagePath);
|
||||
await uploadImage(File(capturedImage.path));
|
||||
|
||||
extractByAPI(AppLink.server + '/card_image/' + box.read(BoxName.driverID));
|
||||
}
|
||||
|
||||
Future extractByAPI(String imgUrl) async {
|
||||
var headers = {'apikey': 'K89368168788957'};
|
||||
var request = http.MultipartRequest(
|
||||
'POST', Uri.parse('https://api.ocr.space/parse/image'));
|
||||
request.fields.addAll({
|
||||
'language': 'ara',
|
||||
'isOverlayRequired': 'false',
|
||||
'url': imgUrl,
|
||||
'iscreatesearchablepdf': 'false',
|
||||
'issearchablepdfhidetextlayer': 'false'
|
||||
});
|
||||
|
||||
request.headers.addAll(headers);
|
||||
|
||||
http.StreamedResponse response = await request.send();
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
print(await response.stream.bytesToString());
|
||||
} else {
|
||||
print(response.reasonPhrase);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Future<void> takePictureAndMLGoogleScan() async {
|
||||
try {
|
||||
// Construct the path for the image file
|
||||
|
||||
Reference in New Issue
Block a user