This commit is contained in:
Hamza-Ayed
2023-10-20 22:16:31 +03:00
parent 02bdc83e72
commit a5afb32990
15 changed files with 533 additions and 7 deletions

View File

@@ -0,0 +1,37 @@
import 'package:get/get.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:google_ml_kit/google_ml_kit.dart';
class TextRecognizerController extends GetxController {
// The ImagePicker instance
final ImagePicker _imagePicker = ImagePicker();
// The GoogleMlKit TextRecognizer instance
final TextRecognizer _textRecognizer = TextRecognizer();
// The scanned text
String? scannedText;
// 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;
}
// Recognize the text in the image
final RecognizedText recognizedText =
await _textRecognizer.processImage(image as InputImage);
// Extract the scanned text
scannedText = recognizedText.text;
// Update the UI
update();
}
}