10/20/1
This commit is contained in:
37
lib/controller/firebase/ml_kit.dart
Normal file
37
lib/controller/firebase/ml_kit.dart
Normal 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user