fix OCR in apx
This commit is contained in:
+15
-2
@@ -103,10 +103,17 @@ class _ScanScreenState extends State<ScanScreen> {
|
||||
_error = 'No text found in this image.';
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
} on PlatformException catch (error) {
|
||||
debugPrint('OCR failed: ${error.code} ${error.message}');
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_error = 'Could not read text from this image.';
|
||||
_error = _ocrFailureMessage(error.message);
|
||||
});
|
||||
} catch (error) {
|
||||
debugPrint('OCR failed: $error');
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_error = _ocrFailureMessage(error.toString());
|
||||
});
|
||||
} finally {
|
||||
await recognizer.close();
|
||||
@@ -120,6 +127,12 @@ class _ScanScreenState extends State<ScanScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
String _ocrFailureMessage(String? detail) {
|
||||
const fallback = 'Could not read text from this image.';
|
||||
if (detail == null || detail.trim().isEmpty) return fallback;
|
||||
return '$fallback\n$detail';
|
||||
}
|
||||
|
||||
Future<void> _openReview(String rawText) async {
|
||||
final items = ReceiptParser.parse(rawText);
|
||||
if (!mounted) return;
|
||||
|
||||
Reference in New Issue
Block a user