From 3979086c1009cb83f32b1a0b24f7bcfb5157af4f Mon Sep 17 00:00:00 2001 From: Johan Jongsma Date: Sat, 31 Jan 2026 19:44:42 +0000 Subject: [PATCH] feat(input): Wire up camera and OCR scanner buttons --- lib/features/input/input_screen.dart | 65 ++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 8 deletions(-) diff --git a/lib/features/input/input_screen.dart b/lib/features/input/input_screen.dart index 9721734..e3f3867 100644 --- a/lib/features/input/input_screen.dart +++ b/lib/features/input/input_screen.dart @@ -210,17 +210,66 @@ class _InputScreenState extends State { } void _onCameraTap() { - // TODO: Implement camera capture - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar(content: Text('Camera - Coming soon')), - ); + // Camera tap also opens OCR scanner (same functionality) + _openOcrScanner(); } void _onOcrTap() { - // TODO: Implement OCR scanning - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar(content: Text('OCR - Coming soon')), - ); + _openOcrScanner(); + } + + Future _openOcrScanner() async { + if (_isProcessing) return; + + setState(() => _isProcessing = true); + + try { + final result = await Navigator.of(context).push( + MaterialPageRoute( + builder: (context) => const OcrCaptureScreen( + enableLivePreview: true, + keepImage: false, + ), + ), + ); + + if (result != null && result.text.isNotEmpty) { + // Append or replace text based on current content + if (_textController.text.isEmpty) { + _textController.text = result.text; + } else { + // Append with newline separator + _textController.text = '${_textController.text}\n\n${result.text}'; + } + + // Move cursor to end + _textController.selection = TextSelection.fromPosition( + TextPosition(offset: _textController.text.length), + ); + + if (mounted) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text('Extracted ${result.blocks.length} text blocks'), + backgroundColor: Colors.green, + ), + ); + } + } + } catch (e) { + if (mounted) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text('OCR failed: $e'), + backgroundColor: Colors.red, + ), + ); + } + } finally { + if (mounted) { + setState(() => _isProcessing = false); + } + } } void _onVoiceTap() {