import 'package:flutter/services.dart'; import 'dart:io'; import 'package:flutter_tesseract_ocr/flutter_tesseract_ocr.dart'; import 'package:path_provider/path_provider.dart'; class ImageUploader { ImageUploader(); Future buildImageFile(String img) async { String imageName = img; ByteData bytes = await rootBundle.load('assets/$imageName'); return bytes.buffer.asUint8List(); } Future performOcr( Uint8List imageBytes, String imageName, String lang) async { Directory tempDir = await getTemporaryDirectory(); String tempPath = tempDir.path; File tempImageFile = File('$tempPath/$imageName'); await tempImageFile.writeAsBytes(imageBytes); String text = await FlutterTesseractOcr.extractText(tempImageFile.path, language: lang, args: { "psm": "4", "preserve_interword_spaces": "1", }); return text; } Future performAdvancedOCR( Uint8List imageBytes, String imageName, String lang) async { Directory tempDir = await getTemporaryDirectory(); String tempPath = tempDir.path; File tempImageFile = File('$tempPath/$imageName'); await tempImageFile.writeAsBytes(imageBytes); String text = await FlutterTesseractOcr.extractHocr(tempImageFile.path, language: lang, args: { "psm": "4", "preserve_interword_spaces": "1", }); return text; } }